[英]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 但是进入捕获后,它不会重定向到错误页面,而是转到master的page_load然后page_load,然后显示错误
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.
说明:执行当前Web请求期间发生未处理的异常。 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. 异常详细信息:System.FormatException:输入字符串的格式不正确。
what is wrong??? 怎么了???
You need to register the routes in application_start
event to tell server which page to call for given string. 您需要在
application_start
事件中注册路由,以告诉服务器为给定字符串调用哪个页面。
In your Global.asax
file write following: 在您的
Global.asax
文件中,输入以下内容:
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. 请参阅此帖子以获取更多详细信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.