asp.net 基本路由不起作用

asp.net basic routing not working

我正在处理 asp.net 网络表单,我在路由方面遇到了一些问题,以下路由无法正常工作:

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

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

尝试 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
}