我得到的错误是
A route named 'xxxxx' could not be found in the route collection.
Parameter name: name
全球性的asax
<%@ Application Language="C#" %>
<%@ Import Namespace="System.Web.Routing" %>
<script runat="server">
public static void RegisterRoutes(RouteCollection routes)
{
routes.MapPageRoute("test2-testurl", "test2/{category}", "~/test2.aspx");
}
void Application_Start(object sender, EventArgs e)
{
RegisterRoutes(RouteTable.Routes);
// Code that runs on application startup
}
void Application_End(object sender, EventArgs e)
{
// Code that runs on application shutdown
}
void Application_Error(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs
}
void Session_Start(object sender, EventArgs e)
{
// Code that runs when a new session is started
}
void Session_End(object sender, EventArgs e)
{
// Code that runs when a session ends.
// Note: The Session_End event is raised only when the sessionstate mode
// is set to InProc in the Web.config file. If session mode is set to StateServer
// or SQLServer, the event is not raised.
}
</script>
在页面test1
中,我在按钮点击事件中编码如下:
protected void Button1_Click(object sender, EventArgs e)
{
string url = Page.GetRouteUrl("test2-testurl", new { category = "laptops" });
Response.RedirectToRoute(url);
}
答案 0 :(得分:0)
也许试试这个(删除'test2'):
routes.MapPageRoute("test2-testurl", "{category}", "~/test2.aspx");
<强>更新强> 尝试以这种方式重定向到页面
Response.Redirect("page2/laptops");
示例:
// add route
routes.MapPageRoute("ad-view", "view/{ad-id}", "~/ad_view.aspx");
// on page I usualy bind values in repeater to links like this:
<asp:HyperLink ID="TitleHL" NavigateUrl='<%# "view/" + Eval("ad_id") %>' runat="server">
// to redirect from code-behind i'll use:
Responce.Redirect("view/" + ad_id);