2011-03-24 63 views
1

我在我的項目中使用UrlRewritting。所有的功能工作正常,但我不能使用ASP.NET AJAX如updatePanel等問題是ScriptResource.axd文件丟失(404錯誤)。在使用UrlRewritting之前,我使用了很多的ASP.net Ajax控件,所以我不能更改整個代碼.....UrlRewritting影響ASP.NET AJAX

  1. 我該如何啓用ASP.NET Ajax?
  2. 可以替代ASP.NET AJAX而不更改代碼隱藏。

回答

4

您必須配置URL在web.config文件重寫模塊。

取反所有個.axd或.SVC或任何或任何的jQuery或WebService請求或任何特異性文件或URL。

例如..

<rule name="Lower Case URLs" stopProcessing="true"> 
     <match url="[A-Z]" ignoreCase="false"/> 
     <conditions logicalGrouping="MatchAll" trackAllCaptures="false"> 
     <add input="{URL}" pattern="WebResource.axd" negate="true"/> 
     <add input="{URL}" pattern="ScriptResource.axd" negate="true"/> 
     <add input="{URL}" pattern="CIMService.svc" negate="true"/> 
     </conditions> 
     <action type="Redirect" url="{ToLower:{URL}}"/> 
    </rule> 
    <rule name="Trailing Slash" stopProcessing="true"> 
     <match url="(.*[^/])$"/> 
     <conditions logicalGrouping="MatchAll" trackAllCaptures="false"> 
     <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/> 
     <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/> 
     <add input="{URL}" pattern="WebResource.axd" negate="true"/> 
     <add input="{URL}" pattern="ScriptResource.axd" negate="true"/> 
     <add input="{URL}" pattern="CIMService.svc" negate="true"/> 
     </conditions> 
     <action type="Redirect" url="{R:1}/"/> 
    </rule> 
1

添加明確避免阻塞或重新路由的所有文件個.axd的規則。

的MVC項目例如有這個具體路線例外:

routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 

這確保阿賈克斯(除其他事項外)正常工作。