2011-04-28 55 views
0

我在項目中有一個例外: 路徑'/Content/Images/CustomFavicon.ico'的控制器未找到或未實現IController。路徑圖標控制器沒有實現IController,正則表達式

我已經找到答案在這裏:I'm getting a "Does not implement IController" error on images and robots.txt in MVC2

這給了我我的問題,併爲IT解決方案的描述。

但是我在正則表達式上很弱,所以也有同樣的問題。 如何修改這個表達式數學圖標表達的兩個路徑,例如下面:

(/.*)?CustomFavicon.ico?(/.*) 

如果我的HTML鏈接文件看起來

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head id="ctl00_Head1"> 
    <link rel="shortcut icon" HREF="/Content/Images/CustomFavicon.ico"> 
    <link rel="icon" href="/Content/Images/CustomFavicon.ico" type="image/x-icon"><title> 
    Home Page 
    </title></head> 
<body> 

acodring到我的測試(見下文),它只認定一個匹配其中還包含HTML我不想:

在這裏看到我的測試:http://regexr.com?2tl4a

這是要在我的Global.aspx使用文件:

routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 
    routes.IgnoreRoute("{resource}.aspx/{*pathInfo}"); 
    //ignore route for ico files 
    routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?CustomFavicon.ico(/.*)?" }); 

回答

0

從您的正則表達式我不知道你想匹配什麼。我修改了一下,以便兩條路徑匹配。

(?:\/.*?)CustomFavicon.ico 

here your modified example

如果你想有這樣一個捕獲組,然後把它周圍的括號,如:

((?:\/.*?)CustomFavicon.ico) 
+0

我需要添加例外忽略ICO文件路由到我的global.aspx,看我原來的文章 – cpoDesign 2011-04-28 13:23:04

+0

@Pavel,我還沒有真正的想法Global.aspx文件是什麼好。我的正則表達式將兩個路徑匹配到* .ico文件。如果你需要別的東西來匹配或不匹配,那麼請指定它可以提高我的正則表達式。 – stema 2011-04-28 13:44:29

+0

嗨,我將能夠在星期二這樣做,它仍然匹配正則表達式,謝謝你:) – cpoDesign 2011-04-28 18:07:30