asp.net基本路由无法正常工作

时间:2016-01-11 09:34:37

标签: asp.net routing url-routing

我正在使用asp.net网络表单,我遇到了一些路由问题,路由无效:

RouteTable.Routes.Add(new Route("{resource}.axd/{*pathInfo}", new StopRoutingHandler()));    
RouteTable.Routes.MapPageRoute("category", "en/Product/{ProductName}", "~/en/index.aspx");

我想知道的是: http://localhost:5562/en/Product.aspx?ProductName=Laptop

1 个答案:

答案 0 :(得分:0)

尝试http://localhost:5562/en/Product/Laptop作为浏览器路线。

然后,根据您的评论,如果您想禁止某个值,请在您的代码中执行此操作,该代码读取index.aspx中的值(如果您使用的话,则执行product.aspx):

string value = Page.RouteData.Values("ProductName"); // get the product being searched for from the URL
List<string> forbiddenValues = new List<string> { "Computer", "BadWord2", "BadWord3" }; // put your forbidden terms in here
if (forbiddenValues.Contains(s, StringComparer.CurrentCultureIgnoreCase)) // case-insensitive
{
    // Bad value detect - throw error or do something
    MyLiteral.Text = "Bad term found.  Cannot continue";
} else
{
    // do you database stuff here and get the products
}