protected void Application_BeginRequest(object sender, EventArgs e)
{
const int maxFileSizeKBytes = 10240; //10 MB
const int maxRequestSizeKBytes = 305200; //~298 MB
if (Request.ContentLength > (maxRequestSizeKBytes * 1024))
{
Response.Redirect(".aspx?requestSize=" + Request.ContentLength.ToString());
}
for (int i = 0; i < Request.Files.Count; i++)
{
if (Request.Files[i].ContentLength > (maxFileSizeKBytes * 1024))
{
Response.Redirect(".aspx?fileSize=" + Request.Files[i].ContentLength.ToString());
}
}
}
This code is in Global.asax.cs page.
I need to redirect to the page that triggered this check. And I need to know the ticketId or projectId parameter. For example I create new ticket at the View Project page /Project/ViewProject.aspx?projectId=1 I need to redirect to this page with a meaningful message to the user, because I think that redirecting to another page to display the error message is not a good idea.
Why don’t you put these checks in the Load handler of a base Page class that ViewProject (and anything else needing the checks) derives from? Then you can just make an error Label visible if the check fails. Untested code:
This way you stay on the same page and you already have ticketId and projectId.