我正在尝试使用.NET3.1中的MVC核心架构运行windows身份验证。我已经设置了一个运行Windows身份验证的项目,但每次启动该应用程序时,它都会直接以我在本地计算机上登录时使用的用户名登录。我需要它始终提示我,因为该应用程序将在公司范围内使用,我不想允许任何用户登录到它,此外,我希望它可以让管理员从我的计算机登录,这样就不会总是我登录。
让我知道如何在每次启动应用程序时手动强制登录提示。如果只有在单击按钮时才打开登录提示,那就更好了。
index.cshtml
@{
ViewData["Title"] = "Home Page";
}
You have loggin in as @User.Identity.Name
@User.Identity.AuthenticationType
@User.Identity.Name
@User.Identity.IsAuthenticated
lanchsettings.json
"iisSettings": { "windowsAuthentication": true, "anonymousAuthentication": false, "iisExpress": { "applicationUrl": "http://localhost:65086", "sslPort": 44374 } }, "profiles": { "IIS Express": { "commandName": "IISExpress", "launchBrowser": true, "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } }, "WindowsAuth": { "commandName": "Project", "launchBrowser": true, "applicationUrl": "https://localhost:5001;http://localhost:5000", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } } } }
HomeController.cs
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using WindowsAuth.Models;
namespace WindowsAuth.Controllers
{
public class HomeController : Controller
{
private readonly ILogger _logger;
public HomeController(ILogger logger)
{
_logger = logger;
}
[Authorize]
public IActionResult Index()
{
return View();
}
public IActionResult Privacy()
{
return View();
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
}
}
如果您认为我需要添加更多相关信息,请发表意见。
您无法使用Windows身份验证执行此操作。如果需要登录提示,则应使用表单身份验证。如果您不想允许所有用户使用应用程序,您可以使用角色: User.IsInRole(&Q;域名组名称&Q;);
仅当您发送请求的工作站不是使用Windows身份验证的域的一部分时,Windows身份验证才会提示输入用户和密码。
这篇关于强制.NET 3.1中的窗口身份验证始终提示输入用户名和密码才能登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持吉威生活!
[英文标题]Force widows authentication in .NET 3.1 to always prompt for username and password to login
声明:本媒体部分图片、文章来源于网络,版权归原作者所有,如有侵权,请联系QQ:330946442删除。