2016-02-26 114 views
1

我已经彻底研究过这个项目,在我看来,做正确的事情。但是,它不起作用,所以我的意见一定是错的!IIS重写规则无法按预期方式工作

我有一个网站,其中所有的内容都在wwwroot或其他文件夹中。 我想让HTML5网址正常工作。 该网站提供了5种URL类型。

  1. 一个空的URL。
  2. 用于物理文件,例如CSS,HTML或JS文件
  3. 的URL/API的URL/...访问资源
  4. 的URL /的OAuth /认证
  5. 的HTML5标记URL类型,说/公司简介

我在web.config中

<rule name="index.html as document root" stopProcessing="true"> 
     <match url="^$" /> 
     <action type="Rewrite" url="/wwwroot/index.html" /> 
    </rule> 
    <rule name="static dist files" stopProcessing="true"> 
     <match url="^(.+)$" /> 
     <conditions> 
     <add input="{APPL_PHYSICAL_PATH}wwwroot\{R:1}" matchType="IsFile" /> 
     </conditions> 
     <action type="Rewrite" url="/wwwroot/{R:1}" /> 
    </rule> 
    <rule name="api call" stopProcessing="true"> 
     <match url="^/api/" /> 
     <action type="None"/> 
    </rule> 
    <rule name="authorization call" stopProcessing="true"> 
     <match url="^/oauth/token$" /> 
     <action type="None"/> 
    </rule> 
    <rule name="reroute html5 to index.html" stopProcessing="true"> 
     <match url="^.+$" /> 
     <action type="Rewrite" url="/wwwroot/index.html" /> 
    </rule> 

以下重写规则我看不到我在做什么错。我能找到的关于“stopProcessing”的文档是不精确的,但我假设它意味着如果规则匹配,不要处理更多规则。

发生的情况是,没有调用API或用于身份验证的正确处理 - 通过调试API不被调用,而是将其重写为wwwroot/index.html。

我确信我正在做一些非常简单的事情,但我已经尝试过所有我能想到的事情。

任何帮助表示赞赏。

服务器正在使用OWIN和JWT,而前端是AngularJS。我正在使用VS2015社区进行开发。

回答

0
<defaultDocument> 
    <files> 
    <clear /> 
    <!-- This is the root document for the Angular app --> 
    <add value="wwwroot/index.html" /> 
    </files> 
</defaultDocument> 

<rewrite> 
    <rules> 

    <rule name="static dist files" stopProcessing="true"> 
     <match url="^(.+)$" /> 
     <conditions> 
     <add input="{APPL_PHYSICAL_PATH}wwwroot\{R:1}" matchType="IsFile" /> 
     </conditions> 
     <action type="Rewrite" url="/wwwroot/{R:1}" /> 
    </rule> 

    <rule name="Main Rule" stopProcessing="true"> 
     <match url=".*" /> 
     <conditions logicalGrouping="MatchAll"> 
     <!-- Allows "api/" prefixed URLs to still hit Web API controllers 
         as defined in WebApiConfig --> 
     <add input="{REQUEST_URI}" pattern="api/" ignoreCase="true" negate="true" /> 
     <!-- Allow "oauth/token" to do autnentication --> 
     <add input="{REQUEST_URI}" pattern="oauth/token" ignoreCase="true" negate="true"/> 
     </conditions> 
     <action type="Rewrite" url="/" /> 
    </rule> 

    </rules> 
</rewrite> 

经过大量的试验和错误,我终于得到它的工作,现在我有它的工作,这都是显而易见的。

defaultDocument负责原始问题中的案例1。 “静态dist文件”规则处理案例2. “主规则”负责处理案例5,确保案件3和案例4不变。