文件上传错误到远程托管vb.net

时间:2012-03-16 12:58:54

标签: asp.net file-upload hosting access-denied

我在远程托管的网站上遇到以下错误。我是第一次部署它,代码就像我的Local Machine上的魅力一样。这似乎是一个权限问题,我不需要担心许可事情,因为我上传到应用程序目录中的文件夹。我不需要为这个仪式授予特别许可吗?所以我试图联系我的托管服务提供商,他们说他们没有任何关系。是否通常在网络托管帐户上设置我可以授予应用程序的权限,或者如何解决此问题?我需要冒充用户吗?我不应该。该文件夹存在于网站上,网站上还有其他歌曲。访问它们没问题。希望有人可以指出我发生了什么。我刚买了远程托管,我不明白它们是如何工作的。

非常感谢。

我的上传代码

      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(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)+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(String path,FileMode mode)+71    System.Web.HttpPostedFile.SaveAs(String filename)+99    profile.btnUpload_Click(Object sender,EventArgs e)+1231

[例外:数据错误:未添加记录]    profile.btnUpload_Click(Object sender,EventArgs e)+1374    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

2 个答案:

答案 0 :(得分:0)

不正确,您需要上传到文件夹的权限,甚至是应用程序根文件夹。

您的主人应该能够解决这个问题,我敢打赌他们过去曾有过其他用户的类似请求。

答案 1 :(得分:0)

我跟goDaddy有关,他们只是说这与他们无关,因为我有权在他们的主机上做我的空间。虽然这是正确的,但他们没有指出如何解决问题的方向。对我的看法不是很有帮助,从来没有过这种经历我从来没有共享主机帐户。如果是VS,我可以控制IIS设置中的所有内容。所以我正在浏览他们的博客,发现这篇文章解决了这个问题。谢谢你的帮助。

http://support.godaddy.com/help/3970/what-is-the-absolute-or-direct-path-for-my-windows-asp-hosting-account