ASP.NET路由。默认页面

时间:2013-04-26 08:28:17

标签: asp.net routing

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

我想做什么,如果用户输入了错误的网址,他应该被重定向到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"); 

谢谢

1 个答案:

答案 0 :(得分:0)

本文详细介绍了如何实现pagenotfound

custom page not found