Bill Software Engineer
Bill Software Engineer

Reputation: 7792

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? 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:

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.

Upvotes: 0

Views: 157

Answers (1)

Claudio Redi
Claudio Redi

Reputation: 68440

Set up basic authentication on the IIS for your site

To use the UI

Open IIS Manager and navigate to the level you want to manage. For information about opening IIS Manager, see Open IIS Manager (IIS 7). For information about navigating to locations in the UI, see Navigation in IIS Manager (IIS 7).

  • In Features View, double-click Authentication.
  • On the Authentication page, select 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.

  • Click OK to close the Edit Basic Authentication Settings dialog box.

Configure Basic Authentication (IIS 7)

Upvotes: 2

Related Questions