2013-04-26 171 views
2

我在我的ASP.NET應用程序中使用路由。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"); 

謝謝你

+1

也許這可能是一些幫助http://stackoverflow.com/a/14586192/1236044 – jbl 2013-04-26 08:49:25

回答

0

這篇文章詳細講解了如何實現pagenotfound

custom page not found

+0

的正是我需要的。謝謝 – Augis 2013-04-26 09:02:12