从Windows身份验证迁移到登录页面 [英] Migration from Windows Authentication to Login page
本文介绍了从Windows身份验证迁移到登录页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个Blazor服务器端应用程序,其中用户使用来自AD的Windows身份验证进行身份验证,而无需登录页面。由于该应用程序被在同一工作站上工作的多个用户使用,因此出现了一个新的要求,即用户在打开Web应用程序时可以输入他们的Windows登录名。因为否则,他们将必须使用其凭据登录到Windows才能使用其用户名进行身份验证。
我希望只弹出本地Chrome浏览器,用户可以在其中输入用户名和密码来访问页面。你能给我一些提示从哪里开始吗?我什么也找不到。我是否必须自己实现对AD的调用,或者是否有内置中间件为我执行此操作?
到目前为止,我了解到的情况是,在这种情况下我不能使用Windows身份验证,但必须恢复使用其他中间件。
编辑:我停用了Windows身份验证,并设法设置了登录页,并根据AD服务器检查用户/密码:
@layout LoginLayout
@page "/Login"
@using Merbag.DataAccessLayer.UserRecertification
@using System.DirectoryServices
@using System.ComponentModel.DataAnnotations
@inject NavigationManager NavigationManager
@inject AuthenticationStateProvider AuthenticationStateProvider
@inject UserRecertificationContext userRecertContext
@inject NavigationManager navManager
@attribute [AllowAnonymous]
<div class="wrapper fadeInDown">
<div id="formContent">
<!-- Login Form -->
<EditForm Model="@userCredentials" OnValidSubmit="@HandleValidSubmit">
<DataAnnotationsValidator />
<ValidationSummary />
<div class="row">
<div class="col-md-12">
<label>User Name :</label>
<input type="text" @bind-value="userCredentials.UserName" id="login" class="fadeIn second" placeholder="login" />
<ValidationMessage For="@(()=> userCredentials.UserName)" />
</div>
<div class="col-md-12">
<label>Password</label>
<input type="password" @bind-value="userCredentials.Password" id="password" class="fadeIn third" placeholder="password" />
<ValidationMessage For="@(()=> userCredentials.Password)" />
</div>
<input type="submit" class="fadeIn fourth" value="Log In">
</div>
</EditForm>
</div>
</div>
@if (showAuthenticationError)
{
<div class="alert alert-danger" role="alert">
<p>@authenticationErrorText</p>
</div>
}
@code {
private bool showAuthenticationError { get; set; } = false;
private string authenticationErrorText = "";
private AuthenticationUserModel userCredentials { get; set; } = new AuthenticationUserModel();
private void HandleValidSubmit()
{
DirectoryEntry entry = new DirectoryEntry();
entry = new DirectoryEntry("LDAP://myldap");
entry.Username = userCredentials.UserName;
entry.Password = userCredentials.Password;
DirectorySearcher search = new DirectorySearcher(entry);
search.Filter = "(SAMAccountName=" + userCredentials.UserName + ")";
SearchResult result = search.FindOne();
if (result == null)
{
//return false;
}
else
{
navManager.NavigateTo("/Index", true);
}
}
public class AuthenticationUserModel
{
[Required(ErrorMessage = "Username is required.")]
public string UserName { get; set; }
[Required(ErrorMessage = "Password is required.")]
public string Password { get; set; }
}
}
对AD服务器的调用显然起作用了,我收到了用户名和其他信息。现在我很难告诉应用程序这个用户是真正的用户,他应该被视为真正的用户,即<AuthorizeView>
应该可以使用。
推荐答案
Windows身份验证不支持此功能,除非您使用其他域,否则它将显示提示窗口。
有关更多详细信息,您可以查看下面的帖子,它应该对您有帮助。
Force widows authentication in .NET 3.1 to always prompt for username and password to login
这篇关于从Windows身份验证迁移到登录页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文