Link to home
Start Free TrialLog in
Avatar of GlobaLevel
GlobaLevelFlag for United States of America

asked on

ASP.NET - Concerned about File upload security

I am using the following code to upload files ...but I am concerned about security in the sense that its available to the public and I want to be sure only certain extentions can be user...txt or .csv...they are upload address info..but if a hacker comes along...they could upload a file that take over the system..any code to protect ..ideas?

FYI..the whole site has SSL on it..if that makes a difference...
<html>
<head>

    <script language="VB" runat="server">
    
    Sub Button1_Click(sender As Object, e As EventArgs)
        
        if FileUpLoad1.HasFile
            'Uncomment this line to Save the uploaded file
            'FileUpLoad1.SaveAs("C:\SomePhysicalPath" & FileUpLoad1.Filename)
            Label1.Text = "Received " & FileUpLoad1.FileName & " Content Type " & FileUpLoad1.PostedFile.ContentType & " Length " & FileUpLoad1.PostedFile.ContentLength
        else
            Label1.Text = "No uploaded file"
        end if    
        
    end sub
        
    </script>

</head>
<body>

    <h3><font face="Verdana">File Upload</font></h3>

    <form runat=server>

        <asp:FileUpLoad id="FileUpLoad1" AlternateText="You cannot upload files" runat="server" />
        <asp:Button id="Button1" Text="Upload" OnClick="Button1_Click" runat="server" />
        <asp:Label id="Label1" runat="server" />
    </form>

</body>
</html>

Open in new window

Avatar of Jerry Miller
Jerry Miller
Flag of United States of America image

Check out this msdn link:
http://msdn.microsoft.com/en-us/library/aa479405.aspx

It gives you some example on determining the file size and type before uploading.
Avatar of GlobaLevel

ASKER

this is good stuff..thanks...I put an instr code piece b4 the file.upload puts the file on the server to scan for extentions.....

I like the <httpRuntime> ..but I donthave that in my web.config...can I add that? even though its not in there?  My users have to ave an account b4 they can upload..but im still being extra cautious...
ASKER CERTIFIED SOLUTION
Avatar of Jerry Miller
Jerry Miller
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial