
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进行调试,它几乎会立即停止调试会话,并且事件日志中出现以下错误:
“Application ‘MACHINE/WEbroOT/APPHOST/myapp’ with physical root
‘C:\Users\me\myapp’ created process with commandline ‘C:\Program files
(x86)\Microsoft Visual
Studio\2017\Professional\Common7\IDE\Extensions\Microsoft\Web
Tools\ProjectSystem\VSIISExeLauncher.exe -argfile
“C:\Users\me\AppData\Local\Temp\tmpFCA6.tmp”‘ but Failed to Listen on
the given port ‘28353’”.
如果我尝试使用.Usehttpsys注释掉,调试工作但我无法正确验证.
解决方法 卡米洛感谢您的评论,这有助于我指出正确的方向.我从program.cs中删除了Usehttpsys部分并添加了.UseIISIntegration().我还在startup.cs中将services.AddAuthentication(httpsysDefaults.AuthenticationScheme)更改为services.AddAuthentication(IISDefaults.AuthenticationScheme).然后,我在项目属性的“调试”部分选中“启用windows身份验证”,并为“启动”选择“IIS Express”,这一切都有效.我是新的.net核心与windows身份验证,所以我不知道我是否所有设置完全正确,但它的工作,希望,这篇文章有助于指出其他人正确的方向. 总结以上是内存溢出为你收集整理的c# – .net Core 2.1应用程序中的Windows身份验证全部内容,希望文章能够帮你解决c# – .net Core 2.1应用程序中的Windows身份验证所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)