【问题标题】:AngularJS Routing in IISIIS中的AngularJS路由
【发布时间】:2016-07-02 00:48:59
【问题描述】:

我已经开发了托管在 IIS 根目录中的 angularJs 应用程序,即)我让它在 Localhost 中运行。如果我在浏览器中输入 localhost 并回车,我的应用程序就会打开并且运行良好。

问题是,我有一些其他应用程序同时在 localhost 下运行。例如)localhost/hrs、localhost/CMS 等,这些都是 asp.net 应用程序。在我托管 Angular 应用程序后,如果尝试打开我的应用程序,它会在浏览器控制台中显示以下 javascript 错误...

Uncaught Error: ASP.NET Ajax client-side framework failed to load.
ScriptResource.axd:1 Uncaught SyntaxError: Unexpected token <

我多次遇到这两个错误...

我该如何克服这个问题?

仅供参考:- 我已经在我的角度应用程序中实现了路由。还有一件事是 URL 重写,我的 web.config 中如下所示...

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

我是 angularJS 的初学者。

任何人都可以帮助我...

提前谢谢...

【问题讨论】:

  • 当 Angular 应用程序托管在路由中时,您的其他应用程序会受到哪些影响?尝试导航到这些应用程序时是否显示任何错误消息?
  • @ScottLyons 我更新了我的问题...谢谢

标签: javascript html angularjs iis url-rewriting


【解决方案1】:

基于 ASP.NET 的 Web 应用程序经常向 WebResources.axd 文件发出请求,以检索程序集资源并将它们提供给 Web 浏览器。服务器上不存在这样的文件,因为 ASP.NET 在请求 WebResources.axd 时会动态生成内容。因此,如果您有一个 URL 重写规则,该规则仅在请求的 URL 不对应于 Web 服务器文件系统上的文件或文件夹时才进行重写或重定向,那么该规则可能会意外地重写对 WebResources.axd 发出的请求,从而破坏您的应用程序。

如果您在重写规则中添加一个额外的条件,则可以轻松避免此问题:

<rewrite>
      <rules>
        <rule name="AngularJS Routes" stopProcessing="true">
          <match url=".*" />
          <conditions logicalGrouping="MatchAll">
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
            <add input="{REQUEST_URI}"  pattern="ITA_CALENDER_API/(.*)" negate="true" />
            <add input="{URL}" negate="true" pattern="\.axd$" />
          </conditions>
          <action type="Rewrite" url="/" />
        </rule>
      </rules>
    </rewrite>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-19
    • 1970-01-01
    • 1970-01-01
    • 2014-08-28
    • 2017-08-29
    相关资源
    最近更新 更多