开发者

file upload C# asp.net

开发者 https://www.devze.com 2023-04-05 10:19 出处:网络
i am trying to upload files in asp.net and putting a specific path to be saved. windows user. it is outputting me an error :

i am trying to upload files in asp.net and putting a specific path to be saved. windows user.

it is outputting me an error :

System.UnauthorizedAccessException was unhandled by user code
  Message=Access to the path 'C:\Users\USER\Desktop\fyp2\CMS TEST4\CMS\CMS\Upload' is denied. 

my code is:

 var guid = Guid.NewGuid();
 if (File.HasFile)
 {
   var length = File.PostedFile.FileName.ToString().Length;
   var ind = File.PostedFile.FileName.ToString().IndexOf开发者_运维知识库('.');
   var sdfs=guid.ToString()+File.PostedFile.FileName.ToString().Substring(ind, length - ind);
   File.PostedFile.SaveAs("C:\\Users\\USER\\Desktop\\fyp2\\CMS TEST4\\CMS\\CMS\\Upload");

 }


The ASP.NET worker process does not have access rights to that path. By default I believe IIS worker processes run under the Network service account. You can either add write rights for the folder to this account, or set up a new Application Pool with a different identity (i.e. a user that does have write rights).


As simple as the error puts it, your application requires the folder to have proper write permissions.

I'm asuming this is a Web Application. In that case, you'll need that the user which IIS uses to run applications has Write permissions over the specified folder.


The users directory is fairly locked down. If the account the web server is running under is not the specified user, it will not, by default, have access to the path. You can either grant explicit access to that path to the account running your web server, or create a folder with appropriate permissions external to that path and create a link on the user's desktop.


Looks like current user has not permission to save. Before writing try use FileSystemRights with AccessControlType.Allow to know permission info of the destination.

0

精彩评论

暂无评论...
验证码 换一张
取 消