IIS ERRORRSS

8 replies

Last post Oct 02, 2006 09:57 AM by tomkmvp

  • IIS ERROR

    Sep 28, 2006 07:41 AM|abiratsis|LINK

    Hello guys I'm developing a web site in which users can upload their own contents. But due the deployment on the live server a little problem appeared when users upload images. Something strange happens ASP.NET gives the usual exception with message
    -----------------------ERROR-----------------------------------------------
    Access to the path "D:\PROJECTS\RATEIT\WEB\RateItWebClient\content\ima ges\img-category33.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:\PROJECTS\RATEIT\WEB\RateItWebClient\content\ima ges\img-category33.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) 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 write 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:
    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.
    Stack Trace:
    [UnauthorizedAccessException: Access to the path "D:\PROJECTS\RATEIT\WEB\RateItWebClient\content\ima ges\img-category33.jpg" is denied.]
    System.IO.__Error.WinIOError(Int32 errorCode, String str) +393
    System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath, Boolean bFromProxy) +888
    System.IO.FileStream..ctor(String path, FileMode mode) +52
    System.Web.HttpPostedFile.SaveAs(String filename) +48
    RateItWebClient.EditCategory.doUpload(Int32 uniqueId, String& imgFilename) in c:\inetpub\wwwroot\RateIt_Last\RateItWebClient\Edi tCategory.aspx.vb:101
    RateItWebClient.EditCategory.Button1_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\RateIt_Last\RateItWebClient\Edi tCategory.aspx.vb:139
    System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
    System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument) +57
    System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument) +18
    System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +33
    System.Web.UI.Page.ProcessRequestMain() +1292

    -------------------------------------------------------------------------
    The message above usually appears when the IIS DEFAULT USER is trying to access a file and has not enough permissions to do it. But on my application this happens only with the following types of images
    *.jpg
    *.gif
    On the other side the content uploading works perfectlly for the following types of images
    *.bmp
    *.png
    --------------SOURCE CODE-----------------------------------------
    If ImageFile.PostedFile.ContentType = "image/jpeg" Or ImageFile.PostedFile.ContentType = "image/gif" Or ImageFile.PostedFile.ContentType = "image/png" Or ImageFile.PostedFile.ContentType = "image/pjpeg" Or ImageFile.PostedFile.ContentType = "image/x-png" Or ImageFile.PostedFile.ContentType = "image/bmp" Then
    Try
    ImageFile.PostedFile.SaveAs(strFilPathName & strFileSaveAs)
    Me.imageName = strFileSaveAs
    statusMsg.Text = "OK"
    Catch exc
    statusMsg.Text = "FAILED"
    End Try
    --------------END OF SOURCE CODE--------------------------------------

    I checked MIME types on IIS but everything seems to be fine. Does anyone has any idea what is going wrong???

    Thanks in advance
  • Re: IIS ERROR

    Sep 28, 2006 10:16 AM|tomkmvp|LINK

    Did you try the suggested fix?

    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 write 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.

    Tom Kaminski (former IIS MVP 2002-2010)
    http://mvp.support.microsoft.com/
  • Re: IIS ERROR

    Sep 28, 2006 11:46 AM|abiratsis|LINK

    Hello master ;)

    Yes I did try your propossision but the problem still remaining. It looks that there is something like steam-conflict...!!!! Look i as i said on the first message the problem arised when I tried to upload an .JPG (and every .jpg or .gif file-I checked the files they are ok) and after the first exception the problem is permanent. The exception is thrown only with the files of type .jpg and .gif.... mystioursly everything is working well when I try .bmp and .png files..!!!!??? So finally I discovered that the problem is when replacing the existing file a file with the same name exists on the directory and the exception was thrown because the system could not (for some unknown reason) replace the existing file with the new one. But my question why my system choose to replace .bmp and .png files and not the .gif or .jpg files.

    Do you have any idea what is going on my friend?
     

  • Re: IIS ERROR

    Sep 28, 2006 05:46 PM|tomkmvp|LINK

    It doesn't seem to make sense.
    Tom Kaminski (former IIS MVP 2002-2010)
    http://mvp.support.microsoft.com/
  • Re: IIS ERROR

    Sep 28, 2006 11:44 PM|steve schofield|LINK

    This is pretty odd I must say.  I would run Filemon on the web server to see what is actually going on when the file is uploaded.  This could provide some clues.   On a side note, did you grant the IUSR and ASPNET (NETWORK SERVICE) user write permissions?

    Steve Schofield
    Windows Server MVP - IIS
    http://iislogs.com/steveschofield
    http://www.IISLogs.com
    Log archival solution
    Install, Configure, Forget

  • Re: IIS ERROR

    Sep 29, 2006 05:40 AM|abiratsis|LINK

    Hello there thanks for responsing,

    I have granted IUSR on every permission but still exeception was thrown... and then I changed the code as below and it works...

    ------------------------------------CHANGED CODE--------------------------------------------------------

                    Try
                        ImageFile.PostedFile.SaveAs(strFilPathName & strFileSaveAs)
                        Me.imageName = strFileSaveAs
                        statusMsg.Text = "ok"
                    Catch exc
                        statusMsg.Text = "failed"                 
                    Finally
                        ImageFile.PostedFile.InputStream.Flush()
                        ImageFile.PostedFile.InputStream.Close()
                    End Try

     -------------------------------------------------------------------------------------------------------------------------

    What is that my friend any new Microsoft achievement or a simple IO NETWORK conflict during file transfering? 

  • Re: IIS ERROR

    Sep 29, 2006 08:27 AM|tomkmvp|LINK

    The material difference in your code seems to be that you don't check for the mime-type in this version. Could that be where the hang-up was? Network IO wouldn't come into play unless you were trying to save the file to a remote\UNC path.
    Tom Kaminski (former IIS MVP 2002-2010)
    http://mvp.support.microsoft.com/
  • Re: IIS ERROR

    Oct 02, 2006 04:02 AM|abiratsis|LINK

    I check the MIME types in the previous program block but this does not seems to be the problem, in some way the file was not correctly stored in the file system. The next time that ASP.NET was trying to replace it (the files have the same name) the previous exception was thrown. So finally in addition to replace it I tried to delete the existing image(*.gif/*.jpg) first, so I find out that the exception was no more thrown. If I try to delete the code into FINALLY statement the exception is still thrown...!!!
  • Re: IIS ERROR

    Oct 02, 2006 09:57 AM|tomkmvp|LINK

    Try Filemon as Steve suggested.
    Tom Kaminski (former IIS MVP 2002-2010)
    http://mvp.support.microsoft.com/