Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

access denied error

Status
Not open for further replies.

inlandpac

Programmer
Jun 18, 2000
235
US
Hello,

After searching and following the instructions that I found on a number of locations, I am at a loss.

I have a file upload script (very simple) that is trying to upload to c:\tmpfiles

I set permissions for the ASP.NET user as well as the IUSR_{machinename} to have full access to c:\tmpfiles.

I have c:\tmpfiles set up as a virtual directory called tmpfiles (which is why in the code below you see /tmpfiles.

But, I still get the error:

Code:
Server Error in '/' Application.
Access to the path 'C:\tmpfiles' 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 'C:\tmpfiles' 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) 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 8:   Dim i As Integer = InStr(1, StrReverse(strFilePath), "\")
Line 9:   Dim strFileName As String = Mid(strFilePath, (Len(strFilePath) - i) + 2)
Line 10:  strFile.PostedFile.SaveAs("/tmpfiles" & strFileName) 
Line 11:  fileUploading.visible = false     
Line 12:  msg.text =  "File Uploaded ..."


Source File: C:\Inetpub\[URL unfurl="true"]wwwroot\file_upload.aspx[/URL]    Line: 10

Stack Trace:

[UnauthorizedAccessException: Access to the path 'C:\tmpfiles' is denied.]
   System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +2014099
   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) +998
   System.IO.FileStream..ctor(String path, FileMode mode) +65
   System.Web.HttpPostedFile.SaveAs(String filename) +87
   ASP.file_upload_aspx.Page_Load(Object Source, EventArgs E) in C:\Inetpub\[URL unfurl="true"]wwwroot\file_upload.aspx:10[/URL]
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +34
   System.Web.UI.Control.OnLoad(EventArgs e) +99
   System.Web.UI.Control.LoadRecursive() +47
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061


Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.42

Help???
 
Would you like to explain what the problem was so that future readers may benefit?


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
It was a code problem. I rewrote the code to look like:

Code:
            Dim strFileType As String = strFile.PostedFile.ContentType
            Dim intFileSize As Integer = strFile.PostedFile.ContentLength
            Dim strpath As String
            Dim strFileName As String

            strFileName = strFile.PostedFile.FileName

            strpath = Server.MapPath("/tmpfiles/") & strFileName

            strFile.PostedFile.SaveAs(strpath)
            fileUploading.Visible = False
            msg.Text = "File Uploaded ..." & strFileName & " - " & strpath
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top