c# – .net Core 2.1应用程序中的Windows身份验证
我有一个.net Core 2.1 MVC应用程序,它承载一个Angular 6应用程序.我使用的是Visual Studio 2017 15.7.3.我正在尝试设置
Windows身份验证但遇到问题.我按照文档和我的Program.cs和Startup.cs如下:
Program.cs中: using Microsoft.AspNetCore.Server.HttpSys; using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Logging; using NLog.Web; using System; namespace CoreIV_Admin_Core { public class Program { public static void Main(string[] args) { var logger = NLog.Web.NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger(); try { logger.Debug("init main"); CreateWebHostBuilder(args).Build().Run(); } catch (Exception ex) { //NLog: catch setup errors logger.Error(ex,"Stopped program because of exception"); throw; } finally { // Ensure to flush and stop internal timers/threads before application-exit (Avoid segmentation fault on Linux) NLog.LogManager.Shutdown(); } } public static IWebHostBuilder CreateWebHostBuilder(string[] args) => WebHost.CreateDefaultBuilder(args) .UseStartup<Startup>() //.UseHttpSys(options => //{ // options.Authentication.Schemes = AuthenticationSchemes.NTLM | AuthenticationSchemes.Negotiate; // options.Authentication.AllowAnonymous = false; //}) .ConfigureLogging(logging => { logging.ClearProviders(); logging.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Information); }) .UseNLog(); // NLog: setup NLog for Dependency injection } } Startup.cs: using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Server.HttpSys; using Microsoft.AspNetCore.SpaServices.Webpack; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; namespace CoreIV_Admin_Core { public class Startup { public Startup(IConfiguration configuration) { Configuration = configuration; } public IConfiguration Configuration { get; } // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.Configure<CookiePolicyOptions>(options => { // This lambda determines whether user consent for non-essential cookies is needed for a given request. options.CheckConsentNeeded = context => true; options.MinimumSameSitePolicy = SameSiteMode.None; }); services.TryAddSingleton<IHttpContextAccessor,HttpContextAccessor>(); services.AddAuthentication(HttpSysDefaults.AuthenticationScheme); services.AddMvc() .SetCompatibilityVersion(CompatibilityVersion.Version_2_1); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app,IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions { HotModuleReplacement = true }); } else { app.UseExceptionHandler("/Home/Error"); app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseCookiePolicy(); app.UseHttpContext(); app.UseAuthentication(); app.UseMvc(routes => { routes.MapRoute( name: "default",template: "{controller=Home}/{action=Index}/{id?}"); routes.MapSpaFallbackRoute( name: "spa-fallback",defaults: new { controller = "Home",action = "Index" }); }); } } } 如果我取消注释program.cs中的.UseHttpSys部分并按Visual Studio中的play进行调试,它几乎会立即停止调试会话,并且事件日志中出现以下错误:
如果我尝试使用.UseHttpSys注释掉,调试工作但我无法正确验证. 解决方法
卡米洛感谢您的评论,这有助于我指出正确的方向.我从program.cs中删除了UseHttpSys部分并添加了.UseIISIntegration().我还在startup.cs中将services.AddAuthentication(HttpSysDefaults.AuthenticationScheme)更改为services.AddAuthentication(IISDefaults.AuthenticationScheme).然后,我在项目属性的“调试”部分选中“启用Windows身份验证”,并为“启动”选择“IIS Express”,这一切都有效.我是新的.net核心与Windows身份验证,所以我不知道我是否所有设置完全正确,但它的工作,希望,这篇文章有助于指出其他人正确的方向.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- 102.You want to import schema objects of the HR user us
- vb6 – 系统错误&H80004015(-2147467243).该类配置为作
- ruby-on-rails – Rails:使用HAML的App模板/脚本生成器?
- 开始cocos2dx学习小记:MacOS下使用cocos2dx创建项目遇到pe
- 解决Datagridview虚拟模式下闪烁的问题
- 混合开发的大趋势之一React Native手势行为那些事 (1)
- react-native – 在React Native中更改应用程序名称
- Cocos2d-js 3.x: 像素触摸
- 外部的依赖
- react-native – 如何在Android手机上运行React Native应用
- ruby-on-rails – 在Rails中缓存Twitter API调用
- vb.net – 在Visual Studio 2010中获得最佳分辨率
- ruby-on-rails – 如何使用Nokogiri提取子文本?
- c – std :: string实现和表达式模板
- Flex通过Iframe使用activex控件,点击除Iframe的其
- 如何把Papervision3d物体加到 flex中(附 立方体例
- ruby-on-rails – 使用AuthLogic保护内容
- fastjson 对spring mvc 支持,直接返回对象时候,
- vb.net 教程 5-15 图像处理之内存处理 3
- [寒江孤叶丶的Cocos2d-x之旅_24]Cocos2d-x LUA 解