Click here to Skip to main content
14,207,305 members
Rate this:
 
Please Sign up or sign in to vote.
See more:
Hello,

i just deployed a webapp, and am getting the error below. The webapp needs to write to files in the app_data, and am being denied access.

i checked the permission of the webapp virtual directory, and i have all necessary access (read/write) for all users

Can you explain what could be causing the error?
could it be code bug?

thanks

D:\InetPub\vhosts\mysite.com\httpdocs\LicService\App_Data

Server Error in '/LicenseService' Application.
Access to the path 'E:\InetPub\vhosts\mysite.com\httpdocs\Service\App_Data' is denied. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.UnauthorizedAccessException: Access to the path 'E:\InetPub\vhosts\mysite.com\httpdocs\Service\App_Data' is denied. 

ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6) that is used if the application is not impersonating. If the application is impersonating via <identity impersonate="true"/>, the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user. 

To grant ASP.NET access to a file, right-click the file in Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access.

Source Error: 
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. 


Stack Trace: 

[UnauthorizedAccessException: Access to the path 'E:\InetPub\vhosts\mysite.com\httpdocs\Service\App_Data' is denied.]
System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +7716339
System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy) +1162
System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize) +64
System.Xml.XmlDownloadManager.GetStream(Uri uri, ICredentials credentials) +77
System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role, Type ofObjectToReturn) +54
System.Xml.XmlTextReaderImpl.OpenUrlDelegate(Object xmlResolver) +74
System.Threading.CompressedStack.runTryCode(Object userData) +70
System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData) +0
System.Threading.CompressedStack.Run(CompressedStack compressedStack, ContextCallback callback, Object state) +108
System.Xml.XmlTextReaderImpl.OpenUrl() +186
System.Xml.XmlTextReaderImpl.Read() +208
System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace) +112
System.Xml.XmlDocument.Load(XmlReader reader) +108
System.Xml.XmlDocument.Load(String filename) +87
LicService.install.cmbSettingFiles_SelectedIndexChanged(Object sender, EventArgs e) in install.aspx.vb:72
LicService.install.Page_Load(Object sender, EventArgs e) in install.aspx.vb:15
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +50
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627
Posted
Updated 18-Mar-19 21:15pm
Comments
Mohamed Mitwalli 23-Apr-12 3:06am
   
Hi ,
Are you sure you give IIS user full control ??
Cool Smith 23-Apr-12 3:45am
   
yes, i have full control for all users in my control panel virtual directory
Sandeep Mewara 23-Apr-12 3:08am
   
Just confirming, though you said all the permissions are already in place, is the following done:
ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6) that is used if the application is not impersonating. If the application is impersonating via <identity impersonate="true">, the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.

Looks like we are missing some permission somewhere.
Cool Smith 23-Apr-12 3:42am
   
i have full permission for all users as i mentioned ealier
digimanus 23-Apr-12 4:01am
   
which users?
is 'Network service' added to e:\inetpub and all (sub)folders?
E.F. Nijboer 23-Apr-12 4:25am
   
Please read the text very carefully a few times because it is all there. You need to authorize ASPNET, not Network Service.
Cool Smith 23-Apr-12 4:24am
   
hello, i have the following users
Administrators
SYSTEM
myHost Domain User (myUserName)
myHost IIS User (IUSR_myUserName)
myHost IIS WP User (IWPD_122(myUserName))
Sandeep Mewara 23-Apr-12 5:02am
   
Which IIS version you are using?
Cool Smith 23-Apr-12 12:31pm
   
i can't check this version from my host
Guirec 23-Apr-12 7:04am
   
What credentials is your XMLDownloadManager using when getting the stream (see stacktrace) ?
I would say you have an error while reading rather than when writing. Did you try to enable anonymous access in IIS?
Cool Smith 23-Apr-12 16:24pm
   
how can i enable anonymous access in IIS in my control panel, and won't this affect security?
Guirec 23-Apr-12 20:09pm
   
This will affect security but give it a try to check if your problem comes from there. You can change that afterwards if issue sits there.
You have to be admin of IIS for that. Are you?
Anup kumar(MCA) 23-Apr-12 7:58am
   
grant permission to users of the network service.
S@53K^S 23-Apr-12 10:50am
   
Best thing to do is keep the file that is being written to from the APP_DATA to some other location like D:Drive or so and try,as windows server will not allow a remote access to non interactive processes,to modify the files.
vr reddy 2-Sep-14 4:55am
   
Hi,

My pdf files there in D Drive
In D drive number of folders. And Each folder contain no.of my pdf files.
So I retrive the path in D Drive. but above exception is raised
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

For Access Denied Error in IIS server for particular file , please follow the below steps

1- Goto to C:\inetpub\wwwroot\YourVirtualDirectortName\toFolderpathWhereFileIsPresent

2- Right click on your file -> Properties -> Pop Up of User properties appears -> click on Security tab-> click on Edit -> select IIS_IUSRS-> tick on Allow Full Control -> Click Ok

This will surely solve the Access denied problem
   
Comments
CHill60 27-May-14 12:15pm
   
Apart from the fact the question is over 2 years old, and is already adequately answered, unless the person following your steps had Admin access they will get the same problem. Also Allow Full Control - see Solution 2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

Please login as administrator and add user

IIS AppPool\DefaultAppPool

and give full permission.

Also check your firewall.
   
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Instead of granting permissions to ASPNET user, grant permissions to NETWORK SERVICE user. Modify permissions within the folder should be enough, no need to give full permissions (no reason to give more permissions than needed)
   
Comments
Fadao 3-Sep-13 11:18am
   
Solution 2 works fine for me. thanks Fadao
Saman With You 16-Oct-16 10:32am
   
Worked for me too. thanks.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Based on the users listed, try:

Add ASPNET user as it might be that ASP.NET is not authorized to access the requested resource. If no impersonation then allow ASPNET user access on that folder Or else if impersonation in Web.config then give access to the impersonated user.
   
Comments
Cool Smith 23-Apr-12 14:48pm
   
how can i use impersonation, note that its a webhost not on my computer
Sandeep Mewara 23-Apr-12 15:56pm
   
In your Web.Config, enable impersonation and then you need to provide access to the impersonated user. But, before this Iwould suggest you to get some access on the host computer as you are trying to deploy on it. As long as you dont have admin rights or so, oit would be really difficult to configure your system properly.
Cool Smith 23-Apr-12 16:51pm
   
does asp.net need admin rights on the web server to run?
Sandeep Mewara 23-Apr-12 16:53pm
   
No. But you might need it to configure the website on webserver.
Cool Smith 23-Apr-12 18:23pm
   
hello, i have the following users which all have read write access. is there some way to set the user to use in my webapp?

Administrators
SYSTEM
myHost Domain User (myUserName)
myHost IIS User (IUSR_myUserName)
myHost IIS WP User (IWPD_122(myUserName))
Cool Smith 23-Apr-12 19:13pm
   
the web.config file in the root directory, does it affect all the site, or only the files in the root directory

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Cookies | Terms of Service
Web01 | 2.8.190612.1 | Last Updated 19 Mar 2019
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100