问题
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.
回答1:
You would typically do this in IIS. See: https://docs.microsoft.com/en-us/iis/configuration/system.webserver/security/authentication/basicauthentication
The short version:
- ensure that the basic authentication feature is enabled on your server
- disable anonymous authentication in your site and enable basic authentication
来源:https://stackoverflow.com/questions/54990475/how-to-create-asp-net-web-page-with-basic-authentication