Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > prevent Upload Large Files .Net

Reply
Thread Tools

prevent Upload Large Files .Net

 
 
Kilic Beg
Guest
Posts: n/a
 
      11-24-2004
Hi,

I want to prevent user to upload files larger than 2MB.
If they try to upload I want to redirect them to a error page (ex: File size
larger than 2 MB )..
right now I get a page break "The page cannot be displayed"

I tried to update the Global.asax.cs file this is the code

protected void Application_BeginRequest(Object sender, EventArgs e)
{
long MAX_CONTENTLENGTH = 2097152;
if (Request.ContentLength > MAX_CONTENTLENGTH) {
//Response.Write("File is to big");
Response.Redirecty("Error.html");
}
}

I put the same code also into
protected void Application_Error(Object sender, EventArgs e)
method..

still page break..

where and how can I catch that and redirect to a friendly error page.
do I have to use a third party product for that ?

Please help !!!

Thanks

- Kilic



 
Reply With Quote
 
 
 
 
Teemu Keiski
Guest
Posts: n/a
 
      11-24-2004
Hi,

you can also set this on web.config. see <httpRuntime> element and
especially maxRequestLength setting
http://msdn.microsoft.com/library/de...imesection.asp

Just note that this effects entire application at once (if it is config file
on app root, on subfolder you can limit it to folder/page level)

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsider
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke


"Kilic Beg" <> wrote in message
news:...
> Hi,
>
> I want to prevent user to upload files larger than 2MB.
> If they try to upload I want to redirect them to a error page (ex: File
> size
> larger than 2 MB )..
> right now I get a page break "The page cannot be displayed"
>
> I tried to update the Global.asax.cs file this is the code
>
> protected void Application_BeginRequest(Object sender, EventArgs e)
> {
> long MAX_CONTENTLENGTH = 2097152;
> if (Request.ContentLength > MAX_CONTENTLENGTH) {
> //Response.Write("File is to big");
> Response.Redirecty("Error.html");
> }
> }
>
> I put the same code also into
> protected void Application_Error(Object sender, EventArgs e)
> method..
>
> still page break..
>
> where and how can I catch that and redirect to a friendly error page.
> do I have to use a third party product for that ?
>
> Please help !!!
>
> Thanks
>
> - Kilic
>
>
>



 
Reply With Quote
 
 
 
 
Kilic Beg
Guest
Posts: n/a
 
      11-24-2004
My problem is not setting the file size limit.

I want to display an error message when the users tries to upload a file
large then in maxRequestLength definied.

right now I have this in my webconfig

<httpRuntime executionTimeout="90" maxRequestLength="4096"
useFullyQualifiedRedirectUrl="false" minFreeThreads="8"
minLocalRequestFreeThreads="4" appRequestQueueLimit="100" />

If the users tries to upload files larger than 4MB he will get a page break
"The page cannot be displayed"..
I want to display a friendly page... (ex: saying the file you trying to
uploading is larger than 4MB)

- Kilic



"Teemu Keiski" <> wrote in message
news:...
> Hi,
>
> you can also set this on web.config. see <httpRuntime> element and
> especially maxRequestLength setting
>

http://msdn.microsoft.com/library/de...imesection.asp
>
> Just note that this effects entire application at once (if it is config

file
> on app root, on subfolder you can limit it to folder/page level)
>
> --
> Teemu Keiski
> MCP, Microsoft MVP (ASP.NET), AspInsider
> ASP.NET Forum Moderator, AspAlliance Columnist
> http://blogs.aspadvice.com/joteke
>
>
> "Kilic Beg" <> wrote in message
> news:...
> > Hi,
> >
> > I want to prevent user to upload files larger than 2MB.
> > If they try to upload I want to redirect them to a error page (ex: File
> > size
> > larger than 2 MB )..
> > right now I get a page break "The page cannot be displayed"
> >
> > I tried to update the Global.asax.cs file this is the code
> >
> > protected void Application_BeginRequest(Object sender, EventArgs e)
> > {
> > long MAX_CONTENTLENGTH = 2097152;
> > if (Request.ContentLength > MAX_CONTENTLENGTH) {
> > //Response.Write("File is to big");
> > Response.Redirecty("Error.html");
> > }
> > }
> >
> > I put the same code also into
> > protected void Application_Error(Object sender, EventArgs e)
> > method..
> >
> > still page break..
> >
> > where and how can I catch that and redirect to a friendly error page.
> > do I have to use a third party product for that ?
> >
> > Please help !!!
> >
> > Thanks
> >
> > - Kilic
> >
> >
> >

>
>



 
Reply With Quote
 
Roger Helliwell
Guest
Posts: n/a
 
      11-25-2004
On Tue, 23 Nov 2004 21:02:51 -0500 in
microsoft.public.dotnet.framework.aspnet.webcontro ls, "Kilic Beg"
<> wrote:

>Hi,
>
>I want to prevent user to upload files larger than 2MB.
>If they try to upload I want to redirect them to a error page (ex: File size
>larger than 2 MB )..
>right now I get a page break "The page cannot be displayed"
>


Kilic,

Not sure how to check the request size, but if you're using one of the
..NET file upload controls (System.Web.UI.HtmlControls.HtmlInputFile or
2.0 FileUpload) you could simply write

System.Web.UI.HtmlControls.HtmlInputFile File1;

if (File1.PostedFile.ContentLength > MAXFILESIZE) {
Response.Redirect("filetoolarge.aspx");
}
else {
// Save the file on the server
}


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
upload very large files =?Utf-8?B?U2FuZHk=?= ASP .Net 2 11-03-2006 04:55 AM
Can not upload large files (>2 megs) to image field. "Cannot find server" message returned... Charlie@CBFC ASP .Net 1 05-03-2005 02:49 AM
Where to upload large files? optxx@juno.com Digital Photography 21 12-17-2004 12:26 AM
Upload large files to server problem Raj Tripathi ASP .Net 1 11-20-2003 02:28 PM
Backing Up Large Files..Or A Large Amount Of Files Scott D. Weber For Unuathorized Thoughts Inc. Computer Support 1 09-19-2003 07:28 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57