Identityserver4在.netCore3上的錯誤記錄日誌
阿新 • • 發佈:2020-09-15
一、報下面的錯誤
{StatusCode: 401, ReasonPhrase: 'Unauthorized', Version: 1.1, Content: System.Net.Http.StreamContent, Headers: { Transfer-Encoding: chunked Date: Tue, 15 Sep 2020 09:35:01 GMT Server: Microsoft-IIS/10.0 WWW-Authenticate: Bearer X-Powered-By: ASP.NET }}
解決方法:
1:漏掉了下面這一行
public voidConfigure(IApplicationBuilder app, IWebHostEnvironment env, IHostApplicationLifetime appLifetime) { System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseRouting();app.UseAuthentication(); //添加了授權中介軟體,以確保匿名客戶端無法訪問我們的API端點。 app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); //程式停止呼叫函式 appLifetime.ApplicationStopped.Register(() => { AutofacContainer.Dispose(); }); }
2、這兩行順序弄反了
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IHostApplicationLifetime appLifetime) { System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseRouting(); app.UseAuthorization();//這順序是錯誤的 app.UseAuthentication();//這順序是錯誤的 //添加了授權中介軟體,以確保匿名客戶端無法訪問我們的API端點。 app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); //程式停止呼叫函式 appLifetime.ApplicationStopped.Register(() => { AutofacContainer.Dispose(); }); }
二、報下面的錯誤
{StatusCode: 500, ReasonPhrase: 'Internal Server Error', Version: 1.1, Content: System.Net.Http.StreamContent, Headers: { Transfer-Encoding: chunked Date: Tue, 15 Sep 2020 09:40:00 GMT Server: Microsoft-IIS/10.0 X-Powered-By: ASP.NET Content-Type: text/plain }}
解決方法如下:
漏掉了下面這一行
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IHostApplicationLifetime appLifetime) { System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseRouting(); app.UseAuthentication(); //添加了授權中介軟體,以確保匿名客戶端無法訪問我們的API端點。 app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); //程式停止呼叫函式 appLifetime.ApplicationStopped.Register(() => { AutofacContainer.Dispose(); }); }