Force widows authentication in .NET 3.1 to always prompt for username and password to login(强制.NET 3.1中的窗口身份验证始终提示输入用户名和密码才能登录)
问题描述
我正在尝试使用.NET3.1中的MVC核心架构运行Windows身份验证。我已经设置了一个运行Windows身份验证的项目,但每次启动该应用程序时,它都会直接以我在本地计算机上登录时使用的用户名登录。我需要它始终提示我,因为该应用程序将在公司范围内使用,我不想允许任何用户登录到它,此外,我希望它可以让管理员从我的计算机登录,这样就不会总是我登录。
让我知道如何在每次启动应用程序时手动强制登录提示。如果只有在单击按钮时才打开登录提示,那就更好了。
index.cshtml
@{
ViewData["Title"] = "Home Page";
}
<div class="text-center">
<h1 class="display-4">You have loggin in as @User.Identity.Name</h1>
<h1>@User.Identity.AuthenticationType</h1>
<h1></h1>
<h1>@User.Identity.Name</h1>
<h1>@User.Identity.IsAuthenticated</h1>
</div>
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<HomeController> _logger;
public HomeController(ILogger<HomeController> 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中的窗口身份验证始终提示输入用户名和密码才能登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:强制.NET 3.1中的窗口身份验证始终提示输入用户名和密码才能登录
- 输入按键事件处理程序 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
