Problems with File Upload

Rate It (1)

Last post 07-31-2008 3:58 AM by winzone. 9 replies.

Sort Posts:

  • Problems with File Upload

    07-27-2007, 7:11 AM
    • Loading...
    • Srenvas
    • Joined on 10-05-2006, 1:57 PM
    • Singapore
    • Posts 5

    Hi all,

    I am trying to upload an image from asp.net 2.0 application using a file upload control. this works fine in my local development machine , but once i have deployed on to the web server, its jus crashing giving "Security Exception" the detailed error msg is something like this

    Security Exception

    Description: The application attempted to perform an operation not allowed by the security policy.  To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.

    Exception Details: System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

    Source Error:

    Line 32:             End If
    Line 33: 
    Line 34:             Dim fi As New IO.FileInfo(fuImage.PostedFile.FileName)
    Line 35:             objServices.ServiceImage = fi.Extension
    Line 36:             Dim PhotoId As Integer = objServicesBO.InsertMrservices(objServices)

    I am given write permission to the folder where i am trying to save my file but still does not work..i one more option i tried is to give acces to ASPNET and NetworkServices users with full control but i dnt see any create user option on the control panel of the web server.. I am using GoDaddy.com webserver..

    Please can any one help me out in this issue.

    Thanks in advance

    Srenvas 

     

    Thanks
    Srenvas
  • Re: Problems with File Upload

    07-27-2007, 8:59 AM

    Did you "contact your system administrator or change the application's trust level in the configuration file?"

    Jeff

    Please: Don't forget to click "Mark as Answer" on the post that helped you. That way future readers will know which post solved your issue.
  • Re: Problems with File Upload

    07-27-2007, 11:34 AM
    • Loading...
    • Srenvas
    • Joined on 10-05-2006, 1:57 PM
    • Singapore
    • Posts 5

    yes the application level config file is alright..i have also communicated with the web server support team but they say there is problem with my script , but i see no problem with my script bcoz its working on my local server. Can you please tell me anything thats specific thats need to be added to the application level config file..

     Thanks

    Srenvas

    Thanks
    Srenvas
  • Re: Problems with File Upload

    08-27-2007, 1:19 PM

    Hi Srenvas,

    I'm not sure if your problem overlaps enough with mine, but I'm using goddaddy as well and could not get a fileupload control to work when I was trying to write a file to a directory ~/images, even though everything worked fine when I ran it locally.

    Here's my fix: I had to create a custom directory via godaddys hosting control center (under content, click on directory management), and give it read, write, and web permissions. It took awhile for the directory to be created, but after it was created and I copied the images to that directory everything worked.

    Hope this helps,
    --john

     

  • Re: Problems with File Upload

    09-12-2007, 11:39 AM

    May b this will help

    <configuration>
    <system.web>
    <identity impersonate="true" userName="xx" password="xx"/>

     

    OR

     

    <configuration>
    <system.web>
    <identity impersonate="true">

     

    (MARK AS ANSWER IS IT SOLVES THE PROBLEM)

  • Re: Problems with File Upload

    09-22-2007, 3:06 AM
    • Loading...
    • bhavana_p
    • Joined on 05-07-2007, 5:47 PM
    • Posts 37

    By Default IIS runs the ASP .NET web application as the Internet user with minimum privileges. So, while accessing any network resources like network drives, printer, files, etc., you need to impersonate a user of the server who has the required privileges. Do this very carefully as this can cause security holes if impersonated an administrative user.

     

    Thanks

    ~B 

  • Re: Problems with File Upload

    05-27-2008, 3:25 AM
    • Loading...
    • bishal33
    • Joined on 05-27-2008, 6:49 AM
    • Posts 1

     

     i am getting this error in the server ... 

     but the code runs well in localhost wht might be the error !

  • Re: Problems with File Upload

    07-15-2008, 12:49 AM
    • Loading...
    • bhavana_p
    • Joined on 05-07-2007, 5:47 PM
    • Posts 37

    Check if the file is accessible by simply opening it through the url. Check if the IIS process has permissions to access it. Check the absolute / relative paths. Try using impersonation.

  • Re: Problems with File Upload

    07-17-2008, 4:58 AM
    • Loading...
    • nazmul_ahsan
    • Joined on 07-15-2008, 9:49 AM
    • Bangladesh
    • Posts 40

    Hi,

    U say that it's a file upload problem, but last time u post a picture that seem to me a "database connection string" error. Please check it out. or If u have problem in file upload u can use following code which is work fine for me at any web server.

     =======================================================

                if(imageUpload.PostedFile.ContentLength == 0)              

     lblmsg.Text = "No file Selected";
                else
                {  
                                        
                    //image upload
                    string fileType = Path.GetFileName(imageUpload.PostedFile.ContentType);
                    if((fileType =="pjpeg")||(fileType =="jpeg"))
                        fileType = "jpeg";
                    if((fileType == "jpeg")||(fileType =="bmp")||(fileType =="jpg"))
                    {                    
                        fileName =imageId.ToString()+"."+ fileType;
                        string destPath = Path.Combine(filePath,fileName);
                        imageUpload.PostedFile.SaveAs(destPath);                        

                    }//End if                

                }//End if

    ====================================== 

    ** Don't forget to mark as "ANSWER" if it's help for you **

    Profanity is the one language all programmers know best.

    Thanks.
    Md. Nazmul Ahsan
  • Re: Problems with File Upload

    07-31-2008, 3:58 AM
    • Loading...
    • winzone
    • Joined on 01-18-2006, 11:44 PM
    • Sg
    • Posts 44

    I think this link will help you to solve the problem,

    http://support.microsoft.com/kb/815147

    Another things that you can write -

    <location allowOverride=false>
    <system.web>
    <securityPolicy>
    <trustLevel name="Full" policyFile="internal"/>
    <trustLevel name="High" policyFile="web_hightrust.config"/>
    <trustLevel name="Medium" policyFile="web_mediumtrust.config"/>
    <trustLevel name="Low" policyFile="web_lowtrust.config"/>
    <trustLevel name="Minimal" policyFile="web_minimaltrust.config"/>
    </securityPolicy>
    <trust level="Medium" originUrl=""/>
    </system.web>
    </location>

    In the web.config file, that can set the browser's TurstLevel. 

    WinZone
Page 1 of 1 (10 items)
Microsoft Communities
Page view counter