Tôi đang cố di chuyển ứng dụng ASP.NET Core 1.1 lên ASP.NET Core 2.0.ASP.NET Core 2.0 HttpSys Xác thực Windows không thành công với thuộc tính Authorize (InvalidOperationException: Không xác thựcScheme được chỉ định)
Ứng dụng này khá đơn giản và bao gồm những điều sau đây:
- Hosted trên HttpSys (trước đây là WebListener)
- Sử dụng Windows authentication:
options.Authentication.Schemes = AuthenticationSchemes.NTLM
- Cho phép xác thực vô danh:
options.Authentication.AllowAnonymous = true
(vì có một số bộ điều khiển không yêu cầu xác thực) - Bộ điều khiển yêu cầu xác thực được trang trí với thuộc tính
[Authorize]
.
Dự án biên dịch và khởi động tốt. Nó cũng phục vụ các hành động của bộ điều khiển không yêu cầu xác thực.
Tuy nhiên, ngay sau khi tôi nhấn một bộ điều khiển với các thuộc tính [Authorize]
, tôi nhận được ngoại lệ sau đây:
System.InvalidOperationException: No authenticationScheme was specified,
and there was no DefaultChallengeScheme found.
at Microsoft.AspNetCore.Authentication.AuthenticationService.<ChallengeAsync>d__11.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Mvc.ChallengeResult.<ExecuteResultAsync>d__14.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.<InvokeResultAsync>d__19.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.<InvokeFilterPipelineAsync>d__17.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.<InvokeAsync>d__15.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Builder.RouterMiddleware.<Invoke>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.<Invoke>d__7.MoveNext()
tôi bắt đầu quan trọng xung quanh với các mẫu dự án và nhận thấy rằng tôi có thể tái sản xuất này dễ dàng sử dụng tiêu chuẩn mẫu Ứng dụng web lõi ASP.NET (Model-View-Controller) bằng Xác thực Windows.
tập tin Các Program.cs được thay đổi như sau:
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseHttpSys(options =>
{
options.Authentication.Schemes = AuthenticationSchemes.NTLM;
options.Authentication.AllowAnonymous = true;
options.MaxConnections = 100;
options.MaxRequestBodySize = 30000000;
options.UrlPrefixes.Add("http://localhost:5000");
})
.UseStartup<Startup>()
.Build();
này xuất phát trực tiếp từ HttpSys documentation. Ngoài ra tôi đã thêm thuộc tính [Authorize]
vào lớp HomeController
. Bây giờ, nó sẽ tạo ra chính xác cùng một ngoại lệ như được hiển thị.
Tôi đã tìm thấy một số bài đăng Stack Overflow có liên quan (here, here và here), nhưng không ai trong số họ giao dịch với Windows Authentication thuần túy (và câu trả lời dường như không khái quát).
ANH YÊU EM https://github.com/aspnet/CORS/issues/60#issuecomment-327484192 – Amivit
Bạn có thể thay IISIntegration.IISDefaults với HttpSys.HttpSysDefaults, chúng xảy ra có cùng giá trị. – Tratcher
Cảm ơn! Đã cập nhật câu trả lời. – Andreas