0

I'm trying to implement some very basic authentication on my site. I want a user/pass popup window to show if a user tries to access any page (like you can access the site by going to http://username:password@mysite.com).

I don't know how to do this, or the best way to do this. The only thing I can think of is maybe using Ajax in my Master Page file? Is there any way to handle this by using a control or something in IIS?

ygetarts
  • 923
  • 3
  • 14
  • 29
  • You want to set up HTTP Basic Authentication in IIS. – SLaks Jul 03 '14 at 15:27
  • Will this allow different users to have different usernames and passwords? I forgot to mention that in my post - I have a database of username/passwords that I need to reference. I'm assuming no. So is doing this with Ajax the only way to go? – ygetarts Jul 03 '14 at 16:46
  • Doing this with AJAX is completely and utterly useless. You need to write server-side code. – SLaks Jul 03 '14 at 18:03
  • Ok. So no AJAX, but I can't do what I need to by using IIS, correct? So I have to write code. What can I use to accomplish this in c#? I've been googling and can't find anything. – ygetarts Jul 03 '14 at 18:35
  • I found this [link](http://blog.stevensanderson.com/2008/08/25/using-the-browsers-native-login-prompt/) which gave me what I was looking for. Thanks for the help. – ygetarts Jul 03 '14 at 19:09

1 Answers1

0

HTTP 401 is a status code that'll trigger the browser's dialog window.

There's another answer that already deals with that, in ASP.NET, here: How to generate an 401 error programmatically in an ASP.NET page

You want this:

Response.ClearContent();
Response.StatusCode = 401;
Response.End();
Community
  • 1
  • 1
Bryan Boettcher
  • 4,412
  • 1
  • 28
  • 49