2つのプロジェクトがあり、1つはMVC(角度を使用)、もう1つはWebAPIです。私はこのpostが、読みAngularから呼び出されたときにWebAPIでWindows認証が機能しない
HTTP Error 401.2 - Unauthorized You are not authorized to view this page due to invalid authentication headers.
Most likely causes:
- No authentication protocol (including anonymous)is selected in IIS.
- Only integrated authentication is enabled, and a client browser was used that does not support integrated authentication.
- Integrated authentication is enabled and the request was sent through a proxy that changed the authentication headers before they reach the Web server.
- The Web server is not configured for anonymous access and a required authorization header was not received.
- The "configuration/system.webServer/authorization" configuration section may be explicitly denying the user access.
:Windows認証は、私はAJAXが、私はエラーを次取得WebAPIのに角度によってMVCサイトから呼び出しを作っていたときに、しかし
MVCで(このarticleのおかげで)正常に動作しています私はJQueryやAngularを使ってHttpClientを呼び出しています。
ご注意:ブラウザからWebAPI URLにヒットした場合、認証が正常に機能します。だからAJAXのリクエストとは何か関係があります。
これは、Global.asaxの
protected void Application_BeginRequest()
{
if (ValidateRequest())
{
//var origin = Request.Headers["Origin"];
Response.Headers.Remove("Access-Control-Allow-Origin");
Response.AddHeader("Access-Control-Allow-Origin", matchedOrigin);
Response.Headers.Remove("Access-Control-Allow-Headers");
Response.AddHeader("Access-Control-Allow-Headers", CustomConfig.HEADERS);
Response.Headers.Remove("Access-Control-Allow-Methods");
Response.AddHeader("Access-Control-Allow-Methods", CustomConfig.METHODS);
}
// This is to avoid "Method 405 Not allowed" error
if (Request.Headers.AllKeys.Contains("Origin") && Request.HttpMethod == "OPTIONS")
{
Response.Flush();
Response.End(); //Send the Empty Response for Options (Preflight Request)
}
}
で私のコードで私は十分に研究を行っているが、解決策を見つけることができませんでした。だからカップル。
- どのように私は上記の問題を解決することができます
- 第二に、私のシナリオ(そして、プロジェクトの設定)に基づいて、Windows認証を使用するための最良の方法は何ですか。
ルーツ。私は信任状で何かをしなければならないと信じていますが、何が分からないのでしょう。 – programmerboy
そして、あなたはSupportsCredentialsを本当に持っています... –
追加の案内のために私の編集を参照してください –