【问题标题】:AngularJS/ c# WebAPI 405 method not allowed after URLrewriteURLrewrite后不允许AngularJS / c#WebAPI 405方法
【发布时间】:2021-07-28 07:40:09
【问题描述】:

我正在尝试让 Oath2 在 AngularJS 中工作。我遇到的问题是redirectURI 中不允许有#,所以我使用HTML5 模式将其删除。

这一切似乎都可以正常工作,直到您刷新任何页面然后找不到 404 页面。

所以我尝试使用下面帖子中包含的 URL 重写来解决此问题

http://www.advancesharp.com/blog/1191/angularjs-html5-mode-reloading-page-not-found-solution

我现在遇到的问题是:

Request URL: http://localhost/companyname/api/public/auth/login
Request Method: POST
Status Code: 405 Method Not Allowed
Remote Address: [::1]:80
Referrer Policy: strict-origin-when-cross-origin

运行站点/api时的结构是

localhost/*companyname*/
localhost/*companyname*/api

*domainname*/*companyname*/
*domainname*/*companyname*/api

我在 angularjs web.config 中的重写规则是

 <rewrite>
  <rules>
    <rule name="Main Rule" 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="/companyname/" />
    </rule>
  </rules>

我使用以下方法在 webapi 中包含了 cors

  var corsAttr = new EnableCorsAttribute("*", "*", "*");
  config.EnableCors(corsAttr);

如果有人能指出我正确的方向,将不胜感激

【问题讨论】:

    标签: c# angularjs asp.net-web-api url-rewriting cors


    【解决方案1】:

    致有类似问题的任何人。

    我最终不得不编写 2 个不同的重写规则,一个用于站点,一个用于 api

    <rewrite>
      <rules>
        <rule name="API Rule" stopProcessing="true">
          <match url="^api/(.*)" />
          <action type="None" />
        </rule>
        <rule name="Main Rule" 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="/companyname/" />
        </rule>
      </rules>
    
    </rewrite>
    

    【讨论】:

      猜你喜欢
      • 2016-12-03
      • 2016-05-06
      • 2014-05-21
      • 1970-01-01
      • 2016-05-15
      • 2019-09-22
      • 2015-11-02
      • 2014-06-21
      • 2017-08-16
      相关资源
      最近更新 更多