2010-07-02 108 views
0

我無法從路由系統中排除不存在的文件。我處理這個代碼在Web窗體的場景:ASP.NET路由ignoreRoute不起作用

public static void RegisterRoutes(RouteCollection routes) 
{ 
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 
    routes.IgnoreRoute("{resource}.gif/{*pathInfo}"); 
    routes.IgnoreRoute("{resource}.jpg/{*pathInfo}"); 
    Route r = new Route("{*url}", new MyRouteHandler()); 
    routes.Add(r); 
} 

當調試

public IHttpHandler GetHttpHandler(RequestContext requestContext) 
{ 
    string path; 

    IHttpHandler page; 

    try 
    { 
     path = requestContext.RouteData.GetRequiredString("url"); 
     LogFile(requestContext, path); 
    } 

路徑仍然包含不存在的GIF文件,JPG等 我要排除具有擴展名的文件如果這是可能的

上面的代碼有問題嗎?訂單是否正確,即在向RouteCollections添加路線之前添加routes.IgnoreRoute條目?

+0

沒有運氣與我下面的答案嗎? – RPM1984 2010-07-02 06:57:17

回答

0

IgnoreRoute是ASP.NET MVC (System.Web.Mvc的擴展方法) - 在Web窗體中不起作用。

這樣做:

routes.Add(new Route("{resource}.gif/{*pathInfo}", new MyIgnoreHandler())); 

您的其他路線地圖到你的正常的處理程序。

你應該從這個問題中刪除「mvc」標籤。