【发布时间】:2012-04-02 00:32:29
【问题描述】:
我的远程主机站点出现以下错误。我第一次部署它,代码就像我的本地机器上的魅力一样。这似乎是一个权限问题,当我上传到应用程序目录中的文件夹时,我不需要担心权限问题。我不需要为那个仪式授予特别许可吗?所以我试图联系我的托管服务提供商,他们说与他们无关。网络托管帐户上通常是否有设置我可以授予应用程序权限或如何解决此问题?我需要模拟用户吗?我不应该。该文件夹存在于网站上,并且网站中还有其他歌曲。访问它们没问题。希望有人能指出我发生了什么。我刚买了远程主机,我不明白它们是如何工作的。
非常感谢。
我的上传代码
If fuSong.HasFile = True Then
Dim conString As String = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
Dim con As New SqlConnection(conString)
Dim location As String = Path.Combine(Server.MapPath("~/Uploads"), fuSong.FileName)
Dim username As String = Page.User.Identity.Name
Dim Insertcommand As New SqlCommand()
Dim prsongname As New SqlParameter("@songname", SqlDbType.NVarChar)
prsongname.DbType = DbType.[String]
prsongname.Value = name
Insertcommand.Parameters.Add(prsongname)
Dim prusername As New SqlParameter("@username", SqlDbType.NVarChar)
prusername.DbType = DbType.[String]
prusername.Value = username
Insertcommand.Parameters.Add(prusername)
Insertcommand.CommandText = "INSERT INTO Songs(Song_Name, UserName) VALUES (@songname, @username)"
Insertcommand.Connection = con
con.Open()
Insertcommand.ExecuteNonQuery()
fuSong.SaveAs(location) ''''''''' I guess error is here
End If
“/”应用程序中的服务器错误。
拒绝访问路径“D:\Hosting\9078263\html\Uploads\Sleep Away.mp3”。
说明:在执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。
异常详细信息:System.UnauthorizedAccessException:对路径“D:\Hosting\9078263\html\Uploads\Sleep Away.mp3”的访问被拒绝。
ASP.NET 无权访问请求的资源。考虑向 ASP.NET 请求标识授予对资源的访问权限。 ASP.NET 有一个基本进程标识(通常是 IIS 5 上的 {MACHINE}\ASPNET 或 IIS 6 和 IIS 7 上的网络服务,以及 IIS 7.5 上配置的应用程序池标识),如果应用程序不是模拟的,则使用该标识。如果应用程序通过 模拟,则身份将是匿名用户(通常是 IUSR_MACHINENAME)或经过身份验证的请求用户。
要授予 ASP.NET 对文件的访问权限,请在资源管理器中右键单击该文件,选择“属性”并选择“安全”选项卡。单击“添加”以添加相应的用户或组。突出显示 ASP.NET 帐户,然后选中所需访问权限的复选框。
来源错误:
在执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪来识别有关异常起源和位置的信息。
堆栈跟踪:
[UnauthorizedAccessException:对路径“D:\Hosting\9078263\html\Uploads\Sleep Away.mp3”的访问被拒绝。] System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +9717806 System.IO.FileStream.Init(字符串路径、FileMode 模式、FileAccess 访问、Int32 权限、Boolean useRights、FileShare 共享、Int32 bufferSize、FileOptions 选项、SECURITY_ATTRIBUTES secAttrs、String msgPath、Boolean bFromProxy、Boolean useLongPath)+1142 System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy) +78 System.IO.FileStream..ctor(字符串路径,文件模式模式)+71 System.Web.HttpPostedFile.SaveAs(字符串文件名) +99 profile.btnUpload_Click(Object sender, EventArgs e) +1231
[异常:数据错误:未添加记录] profile.btnUpload_Click(对象发送者,EventArgs e)+1374 System.Web.UI.WebControls.Button.OnClick(EventArgs e) +118 System.Web.UI.WebControls.Button.RaisePostBackEvent(字符串 eventArgument)+112 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(字符串 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
【问题讨论】:
标签: asp.net file-upload hosting access-denied