2 回答

TA貢獻1811條經(jīng)驗 獲得超4個贊
anonymousAuthentication:true當我設(shè)置時它起作用launchSettings.json:
"iisSettings": {
"windowsAuthentication": true,?
"anonymousAuthentication": true,?
"iisExpress": {
? "applicationUrl": "http://localhost:62148",
? "sslPort": 0
}
從asp.net core中Windows身份驗證和CORS的介紹,我將startup.cs更改如下:
? public void ConfigureServices(IServiceCollection services)
? ? {
? ? ? ? services.AddAuthentication(IISDefaults.AuthenticationScheme);//Add this line
? ? ? ? services.AddCors(c =>
? ? ? ? {
? ? ? ? ? ? c.AddPolicy("AllowOrigin",
? ? ? ? ? ? ? ? options => options
? ? ? ? ? ? ? ? ? ? ? ? //.AllowAnyOrigin()
? ? ? ? ? ? ? ? ? ? ? ? .WithOrigins("http://localhost:4200")
? ? ? ? ? ? ? ? ? ? ? ? .AllowAnyMethod()
? ? ? ? ? ? ? ? ? ? ? ? .AllowAnyHeader()
? ? ? ? ? ? ? ? ? ? ? ? .AllowCredentials()//Add this line
? ? ? ? ? ? ? ? ? ? );
? ? ? ? });
? ? ? ? services.AddMvc()
? ? ? ? ? ? .SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
? ? ? ? ? ? .AddJsonOptions(options =>
? ? ? ? ? ? {
? ? ? ? ? ? ? ? var resolver = options.SerializerSettings.ContractResolver;
? ? ? ? ? ? ? ? if (resolver != null)
? ? ? ? ? ? ? ? ? ? (resolver as DefaultContractResolver).NamingStrategy = null;
? ? ? ? ? ? });
? ? }
? ? public void Configure(IApplicationBuilder app, IHostingEnvironment env)
? ? {
? ? ? ? if (env.IsDevelopment())
? ? ? ? {
? ? ? ? ? ? app.UseDeveloperExceptionPage();
? ? ? ? }
? ? ? ? else
? ? ? ? {
? ? ? ? ? ? // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
? ? ? ? ? ? app.UseHsts();
? ? ? ? }
? ? ? ? app.UseCors("AllowOrigin");
? ? ? ? app.UseMvc();
? ? }
}

TA貢獻1780條經(jīng)驗 獲得超5個贊
我是 .Net Core 的新手,在使用 Windows 身份驗證時遇到類似的問題。我檢查了很多帖子,但沒有一個提供解決方案。通過 MVC 4 或 5 對 applicationhost.config 的更改解決了類似的問題。
我發(fā)現(xiàn)如果我更改端口,應(yīng)用程序?qū)⒁哉{(diào)試模式啟動,并且窗口身份驗證將正常工作。第二次啟動該應(yīng)用程序時,我會收到 401.1 或 401.2 錯誤。
從那以后我改用 Chrome 進行開發(fā),它似乎工作得很好。這并不理想,因為我們的企業(yè)用戶基礎(chǔ)是 IE 或 Edge。
- 2 回答
- 0 關(guān)注
- 211 瀏覽
添加回答
舉報