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中的窗口身份验证始终提示输入用户名和密码才能登录
基础教程推荐
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
