控制器动作由css和地图文件执行

时间:2016-03-29 20:21:08

标签: asp.net angularjs asp.net-mvc asp.net-mvc-routing

我试图将angularjs html5mode与我的asp.net mvc应用程序集成。我已完成大量搜索,他们几乎都说将以下内容添加到您的web.config

<modules runAllManagedModulesForAllRequests="true"/>
<rewrite>
  <rules>
    <rule name="AngularJS Routes" stopProcessing="true">
      <match url=".*" />
      <conditions logicalGrouping="MatchAll">
        <add input="{REQUEST_URI}" pattern="api/" ignoreCase="true" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
      </conditions>
      <action type="Rewrite" url="/" />
    </rule>
  </rules>
</rewrite>

在大多数情况下,一切都按预期工作,但现在我注意到一些文件请求正在触发我的控制器操作方法。例如,如果我执行查看源并单击任何.css链接,我的控制器操作将被执行。我确信还有更多,因为当我添加一个断点时,它被多次调用。

这是我的路线配置:

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

routes.MapRoute(
    name: "Default",
    url: "{controller}/{action}/{id}",
    defaults: new { controller = "App", action = "Index", id = UrlParameter.Optional }
);

这是一个调用我的控制器操作的URL的示例

http://localhost:63952/app/assets/css/style.css

任何帮助都会很棒!

0 个答案:

没有答案
相关问题