Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Ok, so I've found two solutions to this problem. One thanks to Zhaph - Ben Duguid's answer which is an HttpModule that allows ASP.Net to fully manage the authentication.</p> <p>The second solution, and the one that I am going with, is thanks to this question/answer.</p> <p><a href="https://stackoverflow.com/questions/208063/http-authentication-basic-or-digest-in-asp-classic-via-iis/1726629#1726629">HTTP Authentication (Basic or Digest) in ASP Classic via IIS</a></p> <p>I've stripped this down and have a simple test harness that seems to be working well. In this example, instead of a database call, it merely checks that the username and password match and considers that authenticated.</p> <pre><code>using System; using System.Text; namespace AuthenticationTests { public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { string authorisationHeader = Request.ServerVariables["HTTP_AUTHORIZATION"]; if (authorisationHeader != null &amp;&amp; authorisationHeader.StartsWith("Basic ", StringComparison.InvariantCultureIgnoreCase)) { string authorizationParameters = Encoding.Default.GetString(Convert.FromBase64String(authorisationHeader.Substring("Basic ".Length))); string userName = authorizationParameters.Split(':')[0]; string password = authorizationParameters.Split(':')[1]; if (userName == password) //Perform your actual "login" check here. { //Authorised! //Page loads as normal. } else { Unauthorised(); } } else { Unauthorised(); } } private void Unauthorised() { Response.AddHeader("WWW-Authenticate", "Basic"); Response.Status = "401 Unauthorized"; Response.End(); } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload