title: file upload error to remote hosting vb.net
body: <p>I am having the following error on my site on remote hosting. I deployed it for first time and the code just works like a charm on my Local Machine. It seems like a permission issue and I don't need to worry about permission thing as I am uploading into a folder in application directory. I don't need to grant special permission for that rite? So I tried to contact my hosting provider and they said there is nothing to do with them. Is there normally a setting on web hosting account where I can give permission to the application or how do I solve this problem? Do i need to impersonate user ? I should not. The folder exists on the website and there are other songs as well in the website. No problem accessing them. Hope someone can point me out what happen. I just bought the remote hosting and I don't understand how they works.</p>
  
  <p>Thanks a lot. </p>
  
  <p>My upload code</p>
  
  <pre><code>      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
  </code></pre>
  
  <p>Server Error in '/' Application.</p>
  
  <p>Access to the path 'D:\Hosting\9078263\html\Uploads\Sleep Away.mp3' is denied.</p>
  
  <p>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. </p>
  
  <p>Exception Details: System.UnauthorizedAccessException: Access to the path 'D:\Hosting\9078263\html\Uploads\Sleep Away.mp3' is denied. </p>
  
  <p>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 , the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user. </p>
  
  <p>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.</p>
  
  <p>Source Error: </p>
  
  <p>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.</p>
  
  <p>Stack Trace: </p>
  
  <p>[UnauthorizedAccessException: Access to the path 'D:\Hosting\9078263\html\Uploads\Sleep Away.mp3' is denied.]
     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</p>
  
  <p>[Exception: Data error: Record was not added]
     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</p>