如何使用基本身份验证创建ASP.NET网页 [英] How to create asp.net web page with basic authentication

查看:55
本文介绍了如何使用基本身份验证创建ASP.NET网页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆