2

我在我的 ASP.NET 应用程序中使用路由。

我想要做什么,如果用户输入了一些错误的 url,他应该被重定向到 pagenotfound.aspx

例子 :

http://mysite/product/   //<- OK. Goes to all products

http://mysite/product/ipad   //<- OK. Goes to ipad product

http://mysite/somerandomstuff/   //<- NOT OK!! This one should go to pagenotfound.aspx Now I`m getting error:

 Server Error in '/' Application.
--------------------------------------------------------------------------------


 The resource cannot be found.

我的代码是:

//works ok
routes.MapPageRoute(
    "products-all",             
    "product",            
    "~/products.aspx"); 

    //works ok
routes.MapPageRoute(
    "products-category",             
    "product/{category}",            
    "~/product.aspx"); 

//does not work!!!
routes.MapPageRoute(
    "pagenotfound",             
    "",          // <-- what should be here????  
    "~/pagenotfound.aspx"); 

谢谢

4

0 回答 0