简体   繁体   English

在ASP.NET中如何设置需要授权的页面?

[英]In ASP.NET how do I setup a page that require authorization?

I don't mean form athentication. 我不是指形式认证。 You know how some webpage just have a popup in the browser with something along the line of "This webpage require authorization"? 你知道一些网页如何在浏览器中弹出“这个网页需要授权”的内容吗? And you have to enter username/password or it return you a "HTTP Status Code - 401 Unauthorized" error? 你必须输入用户名/密码或它返回“HTTP状态代码 - 401未授权”错误? How do you set that up? 你是如何设置的?

I assume this is done with post header right? 我假设这是用邮件标题完成的吗? Because it doesn't have a form. 因为它没有表格。


On the client end. 在客户端。 I am posting using ServerXMLHTTP using the following code: 我使用以下代码使用ServerXMLHTTP发布:

Dim connection As ServerXMLHTTP
Dim inXML As MSXML2.DOMDocument
Dim outXMLstr, inXMLstr As String
Dim itemsList As IXMLDOMNodeList
Dim itemNode As MSXML2.IXMLDOMNode
Set connection = New ServerXMLHTTP
Set inXML = New DOMDocument
Dim name As String
connection.Open "POST", "http://localhost:46284/", False, CStr("user"), CStr("pass")

In other word, how do I authenticate "user" and "pass" on the server side from the code above. 换句话说,如何从上面的代码验证服务器端的“用户”和“通过”。

Set up basic authentication on the IIS for your site 在IIS上为您的站点设置基本身份验证

To use the UI 要使用UI

Open IIS Manager and navigate to the level you want to manage. 打开IIS管理器并导航到要管理的级别。 For information about opening IIS Manager, see Open IIS Manager (IIS 7). 有关打开IIS管理器的信息,请参阅打开IIS管理器(IIS 7)。 For information about navigating to locations in the UI, see Navigation in IIS Manager (IIS 7). 有关在UI中导航到位置的信息,请参阅IIS管理器中的导航(IIS 7)。

  • In Features View, double-click Authentication. 在“功能视图”中,双击“身份验证”。
  • On the Authentication page, select Basic Authentication. 在Authentication页面上,选择Basic Authentication。
  • In the Actions pane, click Enable to use Basic authentication with the default settings. 在“操作”窗格中,单击“启用”以使用默认设置进行基本身份验证。
  • Optionally, in the Actions pane, click Edit to type the default domain and realm. (可选)在“操作”窗格中,单击“编辑”以键入默认域和域。
  • In the Edit Basic Authentication Settings dialog box, in the Default domain text box, type a default domain or leave it blank. 在“编辑基本身份验证设置”对话框的“默认域”文本框中,键入默认域或将其留空。 Users who do not provide a domain when they log on to your site are authenticated against this domain. 在登录到您的站点时未提供域的用户将针对此域进行身份验证。
  • In the Realm text box, type a realm or leave it blank. 在“领域”文本框中,键入领域或将其留空。 In general, you can use the same value for the realm name as you used for the default domain. 通常,您可以使用与用于默认域的域名相同的值。

Important If you enter the default domain name in the Realm text box, your internal Microsoft Windows domain name may be exposed to external users during the user name and password challenge. 重要说明:如果在“域”文本框中输入默认域名,则在用户名和密码质询期间,您的内部Microsoft Windows域名可能会向外部用户公开。

  • Click OK to close the Edit Basic Authentication Settings dialog box. 单击“确定”关闭“编辑基本身份验证设置”对话框。

Configure Basic Authentication (IIS 7) 配置基本身份验证(IIS 7)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM