为 Web API 配置 Angularjs 路由 URL

Configure Angularjs routing for Web API URL

我开发了 angularjs 应用程序和 Asp.net Web Api。两者都托管在 IIS 服务器的端口 80 中。问题是我无法访问 web api URL 因为 angularjs 路由重定向 API 调用到应用程序的根目录。

Angularjs路由

.when('/home', {
    templateUrl: baseUrl + 'home.html',
       controller: 'homeCtrl'
    })
    .otherwise({
       redirectTo: '/' //Because of this web api call redirect to root of the web app 
    });

我可以为 运行 Web Api 请求配置 angular 路由方法吗?

已编辑

我正在 wb.conf

上使用一些重写规则
<rule name="RemoveTrailingSlash" stopProcessing="true">
                            <match url="(.*)/$" />
                            <conditions>
                              <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                              <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                            </conditions>
                            <action type="Redirect" redirectType="Permanent" url="{R:1}" />
                          </rule>   

                          <rule name="HotelRedirectRulesLenon1" patternSyntax="ECMAScript" stopProcessing="true">
                            <match url=".*" />
                            <conditions logicalGrouping="MatchAny">
                              <add input="{HTTP_HOST}" pattern="^example.(com|net|com.au)$" />           
                            </conditions>
                            <action type="Redirect" url="http://www.example.org" />
                          </rule>
                          <rule name="HotelRedirectRulesLenon2" patternSyntax="ECMAScript" stopProcessing="true">
                            <match url=".*" />
                            <conditions logicalGrouping="MatchAny">            
                              <add input="{HTTP_HOST}" pattern="^www.example.(com.au)$" />
                            </conditions>
                            <action type="Redirect" url="http://www.example.org/{R:0}" />
                          </rule>       
                        <rule name="AngularJS" stopProcessing="true">
                          <match url=".*" />
                          <conditions logicalGrouping="MatchAll">
                            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                          </conditions>
                          <action type="Rewrite" url="/index.html" />
                        </rule>
                        <rule name="Prerender" stopProcessing="true">
                            <match url="^(?!.*?(\.js|\.css|\.xml|\.less|\.png|\.jpg|\.jpeg|\.gif|\.pdf|\.doc|\.txt|\.ico|\.rss|\.zip|\.mp3|\.rar|\.exe|\.wmv|\.doc|\.avi|\.ppt|\.mpg|\.mpeg|\.tif|\.wav|\.mov|\.psd|\.ai|\.xls|\.mp4|\.m4a|\.swf|\.dat|\.dmg|\.iso|\.flv|\.m4v|\.torrent))(.*)" ignoreCase="false" />
                            <conditions logicalGrouping="MatchAny">
                                <add input="{HTTP_USER_AGENT}" pattern="baiduspider|facebookexternalhit|twitterbot" />
                                <add input="{QUERY_STRING}" pattern="_escaped_fragment_" ignoreCase="false" />
                            </conditions>
                            <action type="Rewrite" url="http://example/{R:2}" />
                        </rule>

只需添加以下新的重写规则即可解决我的问题。

<rule name="AngularJS" 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="^/(webApi)" negate="true" />
          </conditions>
          <action type="Rewrite" url="/" />
        </rule>