troubleshooting Question

Can't cancel user request during file upload.

Avatar of CompileError
CompileError asked on
ASP.NETWeb Applications
5 Comments1 Solution966 ViewsLast Modified:
Hello all!
I'm trying to create a kind of code which checks size of file being uploaded and if size exceeds a particular value it should cancel upload and redirect to a page containing error description. In Application_BeginRequest function of global.asax I simply check value of Request.ContentLength and try to redirect if it's bigger than expected by calling the Response.Redirect method. But then I'm getting an "Access is denied" javascript error in IE (in FireFox it just says that "connection to remote host is lost"). Could you please help me to find a solution? This error is making me crazy!
void Application_BeginRequest(object sender, EventArgs e)
	{
		HttpApplication app = sender as HttpApplication;
		if (app.Request.ContentLength > 10000)
		{
		    app.CompleteRequest();
		    Response.Redirect("~/Error.aspx");
		}
	}
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 5 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros