Hi,
In order to handle the error i.e page cannot be dsplayed when we upload file size more than 4 mb using Fileupload control: Iam writing the following code in Global.asax file:
void Application_Error(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs
// Fires when an error occurs Check to see whether we came from the upload form
string fn=System.IO.Path.GetFileName(Request.Path).ToString();
if ( fn== "default.aspx")
{
//Get error details
System.Exception appException=Server.GetLastError();
HttpException checkException=(HttpException) appException;
//Verfy the expected error
int code = checkException.GetHttpCode();
if((code==500) ||(checkException.ErrorCode==-2147467259))
{
// Error 400 = bad request, user
// tried to upload a file that's too large
Session["ImageTooLarge"] = 1;
Server.ClearError();
//Go to the original target page
Response.Redirect("default.aspx");
}
}
and in the Default.aspx page load is like this:
if (!IsPostBack)
{
// Check to see whether we were redirected from the error page
int i=Convert.ToInt32(Session["ImageTooLarge"]);
if (i==1)
{
lblTooLarge.Text = "Exceeded";
}
but still I am getting page not displayed error. When I try to debugg the Application_Error event is firing in that event it is storing 1 into session, but the page is not redirecting to Default.aspx page.
What I am doing wrong.
Thanks in advance.
In order to handle the error i.e page cannot be dsplayed when we upload file size more than 4 mb using Fileupload control: Iam writing the following code in Global.asax file:
void Application_Error(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs
// Fires when an error occurs Check to see whether we came from the upload form
string fn=System.IO.Path.GetFileName(Request.Path).ToString();
if ( fn== "default.aspx")
{
//Get error details
System.Exception appException=Server.GetLastError();
HttpException checkException=(HttpException) appException;
//Verfy the expected error
int code = checkException.GetHttpCode();
if((code==500) ||(checkException.ErrorCode==-2147467259))
{
// Error 400 = bad request, user
// tried to upload a file that's too large
Session["ImageTooLarge"] = 1;
Server.ClearError();
//Go to the original target page
Response.Redirect("default.aspx");
}
}
and in the Default.aspx page load is like this:
if (!IsPostBack)
{
// Check to see whether we were redirected from the error page
int i=Convert.ToInt32(Session["ImageTooLarge"]);
if (i==1)
{
lblTooLarge.Text = "Exceeded";
}
but still I am getting page not displayed error. When I try to debugg the Application_Error event is firing in that event it is storing 1 into session, but the page is not redirecting to Default.aspx page.
What I am doing wrong.
Thanks in advance.