ASP.NET permissions issues - asp.net

Im using Windows Server 2008, IIS7, .NET 4 and when I use the FileUpload control to save a file to a directory I get :
Access to the path 'C:\xxx\Websites\CMS\Admin\test' is denied.
I have given the test folder full control permissions for NETWORK SERVICE but it makes no difference.
I have given full control to the Everyone user but makes no difference.
It might have something to do with the fact that up in the CMS folder there is a MVC web application and in the CMS\Admin folder there is a web forms web application. It is the web forms web application that is trying to upload the file and getting the permissions error.
Can anyone offer a suggestion.

Are you running your application in Medium Trust? Medium Trust does not allow file IO outside of it's own virtual path hierarchy.
Check the web.config for a <trust level="Medium" ... element.

Check the Application Pool that your site is running under and make sure that it is running as NetworkService instead of PoolIdentity.

Related

Install asp.net mvc application on windows server

I have following problem:
there is windows server 2008 r2
it has iis 7.5 installed
I moved my application there (it is asp.net mvc 5 application), installed .net 4.5 framework on the server
ran following command in cmd
%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis.exe -ir
tried also %windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe -ir
but still it throws exception:
403 - Forbidden: Access is denied.
You do not have permission to view this directory or page using the credentials that you supplied.
I enabled directory browsing and only thing that it can make is browse through folders. But it is web application and not file directory to browse.
So can anyone tell me what am I missing?
IIS configuration:
UPDATE 1
IUSR and IIS_IUSRS both have full control
I also tried adding Everyone with full control on the folder where my application is, but still same
make sure that the MVC Dll's are included in the build output of your project.
Also try adding this code to the system.webserver part of your web.config
<modules runAllManagedModulesForAllRequests="true">
https://www.iis.net/configreference/system.webserver/modules
<modules runAllManagedModulesForAllRequests="true" /> Meaning
If you are trying to test your site by launching http://yourdomain.com/ then it will display all files like you are "Browsing the Directory", you have to add a default document - this is the your main or landing page on your web application settings.
On IIS Manager, click your site, on the right pane, under IIS, click Default Document and set the page you want to show first.
"403 - Forbidden: Access is denied" means the IIS doesn't have the rights to access the resources in your application folder. It is usually a problem with the user the IIS uses to access the resources.
Just as a test: give "everyone" the full rights to the directory where your application is located. If this works, remove "everyone" and give the user IIS_IUSRS the rights to read the resources on the directory (maybe this user needs rights to write in the App_Data folder).
go to published folder of your application and give edit update access to iis user to that folder then it will work,
right click on folder
click properties and then click on security and then full control to iis user.

ASP.NET Access to the path denied, on Web Server

I am having a problem, that is when I deployed my asp.net 4.0 application on my web server i am unable to write to App_Data folder. Actually it has an xml file which I am trying to write some information into. I am getting the following error.
Access to the path 'C:\HostingSpaces\hosterind\mydomain.com\wwwroot\App_Data\ErrorLog.xml' is denied.
I tried searching every corner for a possible solution before posting on stackoverflow but i am unable to fix this. Searching similar questions on internet (stackoverflow too) i concluded that i need to handle it through IIS as everywhere it was quoted on internet to grant permission to App_Data folder through IIS Manager. As accessing IIS Manager of your web hosting server is impossible, i supposed people are referring to my local IIS server. So, i copied my project which i was developing in visual studio from location: C:\Users\DanComputer\Documents\Visual Studio 2010\WebSites\MyWebProject and pasted into C:\inetpub\wwwroot. Then i located my project in IIS Manager by selecting DefaultAppPool as application pool. I changed my App_Data folder permission to allow full control for IIS_IUSRS(DanComputer\IISUSRS). Then i copied my App_Data folder to my web hosting space using ftp software but it didn't solve my problem. I tried many thing even changing permission to allow full control for everyone but it did't work and i am still getting the same error. Any help please?
You need to know what is the identity of the Application Pool of your app. You can get this information from IIS or console. It is possible that your hosing company may have a control panel that can give you that information.
Then you need to give permissions to the account in the app pool identity the names will be the same or at least be very similar to what you saw in IIS:
So using my examples above I will have to give permissions to Local Service or Network Service to read/write my app_data folder.

How to grant rights properly to a folder on IIS 7.5 Express

I'm getting a quite common exception: Access to the path 'C:\inetpub\wwwroot\Content\Images\Uploads\<there goes my hashed guid as a subfolder name which is created dynamically>'
I'm using IIS Express 7.5. I'm using WA authentication in my application. Impersonation's disabled both in web.config and on IIS.
I looked at application pool the site is running (which is ASP.NET 4.0). Application pool identity: Network Service. I have given full control rights to the Uploads folder for IIS AppPool\ASP.NET 4.0. Also did this for authenticated users. Checked I did this for subfolders.
EDIT
Helped a little http://forums.asp.net/t/984207.aspx/1
I have created the folder: C:\inetpub\wwwroot\Content\Images\Uploads. It wasn't present on my C drive before). Then I added full control permissions for Network Authority on the folder and successfully uploaded a file to the path.
So I'm just curious where should I keep my project folder? Now I keeping it on other drive, not C.
EDIT
Ok. I understood. All this is connected to my code where Server.MapPath is called.
Thanks!
You must give permission to the Uploads folder for NetworkService witch is the ASP.NET 4.0 identity.

Is it possible to sandbox an ASP.Net site on IIS7.5 without using Medium Trust?

Setting the .Net trust level to Medium on a site will ensure that no code can access files outside the application directory.
I have an ASP.Net site that must run in Full Trust. I have configured my website in IIS to use its own Application Pool Identity (IIS Apppool\www.site-name.com).
Currently it is possible for scripts/code in this app to read files outside of the application directory. This occurs because by default, accounts that are a member of the BUILTIN\users group are able to read most files on the system, including c:\ and c:\windows. It appears that Applicaion Pool Identity accounts are also members of BUILTIN\users.
Is it possible to prevent file access outside the website folder while keeping Full Trust?
How about using file/directory ACL to deny your AppPoolIdentity access to needed folders?

ASP.NET What causes: It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application...?

I have an ASP.NET web site. I keep getting the error below in VS 2008. The site works fine from a browser. I have made every folder using IIS manager an ASP.NET app. Why does it keep complaining? The site's folder is below a parent folder.
I am not familiar with web site apps instead of web application app. Where are the options to use IIS or the internal web server like WAP has?
It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS
I dealed a lot with this error when having more than one web.config in the same virtual web directory / website. It may happen if you make a temporary backup of your website for example. Could you verify it?
This error can occur when you are you redefining stuff in the web.config of your virtual directory that you cannot override. Such as authentication or sessionstate. Try deleting all web.configs in your virtual directories to see if that solves the problem.
You likely have a virtual directory set up as a real site, having a bin directory, aspnet_client and web.config.
Either remove those and run it as a relative path, localhost\subdir\default.aspx, or create a new website in IIS to point directly at it.
My workaround was to move each folder into its own folder under wwwroot.
I resolved this issue by doing the following,
Select your project in Visual Studio and click 'Show all files' under Solution Explorer.
Delete the 'obj' folder and recompile.

Resources