上传文件是报错,没有权限
第一次在托管主机上发布站点,发布都成功了
但是测试站点的时候,发现上传图片的功能每次都报错
报错信息如下:
Server Error in '/' Application.
Access to the path 'd:\sites\internationalyuan\iyuan.com.au\home\photos\20107832332646.jpg' 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 'd:\sites\internationalyuan\iyuan.com.au\home\photos\20107832332646.jpg' 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:
Line 67: savepath = Path.Combine(Request.PhysicalApplicationPath, imagefolder);
Line 68: savefile = Path.Combine(savepath, ImageUpload.FileName);
Line 69: ImageUpload.SaveAs(savefile);
Line 70: //fileExtion = ImageUpload.FileName.Substring(ImageUpload.FileName.LastIndexOf('.') + 1);
Line 71: fileExt = ImageUpload.FileName.Substring(ImageUpload.FileName.LastIndexOf('.') + 1).ToUpper();
Source File: d:\Sites\internationalyuan\iyuan.com.au\home\PhotoUpload.aspx.cs Line: 69
Stack Trace:
[UnauthorizedAccessException: Access to the path 'd:\sites\internationalyuan\iyuan.com.au\home\photos\20107832332646.jpg' is denied.]
System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +12899591
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, Boolean useLongPath) +2481
System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy) +229
System.IO.FileStream..ctor(String path, FileMode mode) +106
System.Web.HttpPostedFile.SaveAs(String filename) +295
PhotoUpload.upload_btn_Click(Object sender, EventArgs e) in d:\Sites\internationalyuan\iyuan.com.au\home\PhotoUpload.aspx.cs:69
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +154
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3707
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272
不知道这个应该怎么解决? 是代码的问题 还是主机运营商的问题?
------解决方案--------------------
主机运营商的问题,你跟他们说一下就可以了
------解决方案--------------------发布后的文件夹权限没有设置好吧,应给NetWork Service用户相应的可读权限。
------解决方案-------------------- 上传文件的文件夹应该是 everyone 权限
------解决方案--------------------目录权限的问题。和服务提供商说