在我的Global.asax中我有这些规则
protected void Application_Start(object sender, EventArgs e)
{
RouteTable.Routes.EnableFriendlyUrls();
RouteTable.Routes.MapPageRoute("", "Home", "~/Default.aspx");
RouteTable.Routes.MapPageRoute("", "Carrello", "~/Carrello.aspx");
RouteTable.Routes.MapPageRoute("", "Checkout", "~/Checkout2.aspx");
RouteTable.Routes.MapPageRoute("", "Ricerca-Prodotto/{Filtri}/{Pagina}", "~/ProductsSearch.aspx");
RouteTable.Routes.MapPageRoute("", "Prodotto/{ProductId}", "~/Product.aspx");
RouteTable.Routes.MapPageRoute("", "Prodotti/{Menu}/{Marca}/{Categoria}/{Pagina}", "~/Product.aspx");
}
我还有UrlRewrite来管理
protected void Application_BeginRequest(object sender, EventArgs e)
{
System.Collections.Generic.List<Rewrite> rewrites = Rewrite.getRules();
String fullOriginalPath = Request.Url.ToString();
int index = 0;
if(fullOriginalPath.Contains("www."))
index = fullOriginalPath.IndexOf('/', fullOriginalPath.IndexOf("e-miko.com")) + 1;
else
index = fullOriginalPath.IndexOf('/', fullOriginalPath.IndexOf("localhost")) + 1;
string chiave = fullOriginalPath.Substring(index);
Utility.WriteToLog(chiave);
foreach (Rewrite r in rewrites)
{
if(r.Chiave == chiave)
{
string url = "/" + r.Pagina;
if (r.Param1 != null)
url += "/" + r.Param1;
if (r.Param2 != null)
url += "/" + r.Param2;
if (r.Param3 != null)
url += "/" + r.Param3;
if (r.Param4 != null)
url += "/" + r.Param4;
if (r.Param5 != null)
url += "/" + r.Param5;
Context.RewritePath(url);
}
}
}
我也尝试将这些行放在web.config
中<httpErrors errorMode="Custom" existingResponse="Replace">
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" path="/PageNotFound.aspx" responseMode="ExecuteURL" />
<remove statusCode="500" subStatusCode="-1" />
<error statusCode="500" path="/PageNotFound.aspx" responseMode="ExecuteURL" />
但我的所有urlRewrite页面都在PageNotFound.aspx
中如果当前的Url未包含在这些规则中,是否有办法将用户重定向到主页? 例如,如果当前url是/ CheckoutError,我该如何将用户重定向到/ Home?
由于
答案 0 :(得分:0)
您的问题与
重复asp.net 4.0 web forms routing - default/wildcard route
你只需要
RouteTable.Routes.MapPageRoute("defaultRoute", "{*value}", "~/Home.aspx");