[英]AngularJS , REST, C# Service, 405 - Post Method Not Allowed
[英]AngularJS/ c# WebAPI 405 method not allowed after URLrewrite
我試圖讓 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);
如果有人能指出我正確的方向,將不勝感激
對於任何有類似問題的人。
我最終不得不編寫 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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.