Quantcast
Channel: Security
Viewing all articles
Browse latest Browse all 1881

ASP.NET file upload

$
0
0

I have web form where I need to upload a file. I have set the maximum file size size as 10mb in web.config file. Now I need to validate the file upload in the form. If I try to upload a file size greater then 10mb it is moving toHTTP Error 404.13 - Not Found page but instead I need to display a error message in the same form as The maximum file has been extended . I used the following code for that purpose.
 

<div class="pre-action-link" id="premain189661"> </div>

 protected void btnSave_OnClick(object sender, EventArgs e)
    {
        if (uxFileUpload.FileBytes.Length > 0 )
        {
            int iMaxFileSize = 2097152;
            if (Request.ContentLength > iMaxFileSize)
            {
                exceedErrormessage.Visible=true; 
                //Server.Transfer("Error.aspx"); 
            }

<div class="pre-action-link" id="premain497006"> </div>

<divclass="file-upload"><asp:LabelID="uiFileUpload"runat="server"AssociatedControlID="uxFileUpload"Text="Select file"/><p>The maximun file size is 20mb</p><asp:FileUploadID="uxFileUpload"runat="server"/><asp:PlaceHolderID="exceedErrormessage"Visible="false"runat="server"><asp:LiteralID="exServerErroemessage"runat="server"Text="The maximum file limit has been exceeded"/></asp:PlaceHolder><%--<asp:Label ID="label" runat="server"></asp:Label>--%><asp:CustomValidatorID="CustomValidator1"runat="server"ControlToValidate="uxFileUpload"ErrorMessage="File size should not be greater than 20 mb."OnServerValidate="btnSave_OnClick"></asp:CustomValidator><asp:ButtonID="btnSaveDocument"ValidationGroup="SaveFile"OnClick="btnSave_OnClick"runat="server"Text="Upload"CssClass="button"/></div>

 
But still it is moving to the same error page when I try to upload a file size greater then 10mb. I even tried placing a breakpoint and checked where the problem is occurring. I found that when I try to upload a file size greater than 10 mb it is not even moving to the btnSave_OnClick function but otherwise if I upload a file size less than 10 mb it is moving to the function and the corresponding operation is been performed. Can anyone help me to solve this problem.


Viewing all articles
Browse latest Browse all 1881

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>