Url routing from Catch() in asp.net 4.0
I have written in my content page
protected void Page_Init(object sender, EventArgs e)
{
try
{
Page.Title = "Bollywood Movie-" + Page.RouteData.Values["MovieName"].ToString();
int movieid = int.Parse(Page.RouteData.Values["MovieId"].ToString());
}
开发者_如何学运维 catch (Exception ex)
{
Response.RedirectToRoute("ErrorPage");
}
}
but after going into catch it doesn't redirect to error page but it goes to page_load then page_load of master then it shows error of
Server Error in '/' Application.
Input string was not in a correct format. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.FormatException: Input string was not in a correct format.
what is wrong???
You need to register the routes in application_start
event to tell server which page to call for given string.
In your Global.asax
file write following:
void Application_Start(object sender, EventArgs e)
{
RouteTable.Routes.MapPageRoute(
"ErrorPage", // Route name
"ErrorPage", // Route URL
"~/ErrorPage.aspx" // Web page to handle route
);
}
Please refer to this post for more details.
精彩评论