Click here to Skip to main content
15,887,328 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
hi When I want upload a file with fileUpload Control in asp.net I get this error on server .
the server use plesk interface.




Server Error in '/' Application.

Access to the path '~\Upload\NewsImage' 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 '~\Upload\NewsImage' 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 and IIS 7, and the configured application pool identity on IIS 7.5) 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 '~\Upload\NewsImage' is denied.]
   System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +9726046
   System.IO.Directory.InternalCreateDirectory(String fullPath, String path, Object dirSecurityObj) +9497018
   System.IO.Directory.CreateDirectory(String path) +146
   GUI.AddNews.btnSave_Click(Object sender, EventArgs e) in D:\My Project\AzadUniv\New\55\GUI\AddNews.aspx.cs:59
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +118
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +112
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1
Posted
Updated 5-Sep-12 9:34am
v2
Comments
[no name] 5-Sep-12 15:35pm    
Screaming and rudeness removed.
Kenneth Haugland 5-Sep-12 15:51pm    
Desparation removed is proberbly also a thing....
[no name] 5-Sep-12 15:54pm    
That too but then I would have to type more letters... :-)
Kenneth Haugland 5-Sep-12 16:54pm    
Its quite amazing what people ask questions about here... Like we are the oracle of delphi or something like it...

The solution comes from your own error message:
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.


Also, here[^], let me Google it for you.

Behnam Mohammadi wrote:
IT'S VERY VERY URGENT PLEASE HELP ME

Now this, we do not like. It may be urgent to everyone and anyone posting a question, but these forums are run by volunteers providing answers in their own free time, trying to help others. No-one gets priority over anyone, no matter how urgentz their issue may be. For this reason, I've downvoted your question
 
Share this answer
 
Comments
[no name] 5-Sep-12 15:34pm    
Nice
Behnam Mohammadi 5-Sep-12 15:37pm    
i can't use iis i user plesk interface and now the site uploded to the server.
Andrei Straut 5-Sep-12 15:43pm    
So, you mean you have no access to the server? Then you how do you upload your sources to it?

If you have no access to the server to modify the file permissions yourself, then you might speak to your hosting company to grant you the access rights you need
Behnam Mohammadi 5-Sep-12 15:53pm    
I have SERVER
I don't know use ISS
my server interface is plesk
this code is path on my computer but i don't know how run in the server GUI.AddNews.btnSave_Click(Object sender, EventArgs e) in D:\My Project\AzadUniv\New\55\GUI\AddNews.aspx.cs:59
i thin the probleem it is.
Step : 1 Go to folder where you want to upload photo
Step : 2 Right click on folder and select properties
Step : 3 Than select security tab and select on Edit button
Step : 4 Window will appear in which , press button "Add"
Step : 5 And in Textarea write "Everyone" , and press ok button
Step : 6 Now select Everyone and Check the checkbox "Full Control" and other as well
Step :7 Finally press Apply button and at last window press ok
 
Share this answer
 
Comments
CHill60 9-Nov-21 5:38am    
You have added nothing new to the solution given by Andrei, nor am I convinced that giving everyone access to the folder is good advice

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900