How to create asp.net web page with basic authentication

◇◆丶佛笑我妖孽 提交于 2021-02-17 05:17:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!