如何使用基本身份验证创建ASP.NET网页 [英] How to create asp.net web page with basic authentication
问题描述
我想创建ASP.NET网页,该网页将提示我基本身份验证弹出窗口,在其中输入凭据.我尝试在PreInit和PreLoad事件处理程序中添加以下代码行,但仍然没有向我显示基本的身份验证弹出窗口.
I want to create ASP.NET web page which will prompt me basic authentication popup where in I will enter credentials. I tried adding below lines of code in PreInit and PreLoad event handlers but still it is not showing me basic authentication popup.
protected override void OnPreInit(EventArgs e)
{
base.OnPreInit(e);
Response.Headers.Add("WWW-Authenticate", "Basic");
}
protected override void OnPreLoad(EventArgs e)
{
base.OnPreLoad(e);
Response.Headers.Add("WWW-Authenticate", "Basic");
Response.AppendHeader("WWW-Authenticate", "Basic");
}
您能帮我吗?预先感谢.
Can you please help me with this ? Thanks in advance.
推荐答案
您通常会在IIS中执行此操作.请参阅: https://docs.microsoft.com/en-us/iis/configuration/system.webserver/security/authentication/basicauthentication
You would typically do this in IIS. See: https://docs.microsoft.com/en-us/iis/configuration/system.webserver/security/authentication/basicauthentication
简短版本:
- 确保在服务器上启用了基本身份验证功能
- 在您的站点中禁用匿名身份验证并启用基本身份验证
这篇关于如何使用基本身份验证创建ASP.NET网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!