title: What is "realm" in IIS authentication and how is it related to SSL certificate parameters?
body: <p>I'm trying to implemented custom basic authentication <a href="http://custombasicauth.codeplex.com/" rel="noreferrer">similar to this</a> and one thing that confuses me is a concept of <em>realm</em>. For example, there's a moment when my module inserts some magic string into the reply:</p>
  
  <pre><code>void ReplyWithAuthHeader()
  {
      HttpContext currentContext = HttpContext.Current;
      context.Response.StatusCode = 401;
      context.Response.AddHeader( "WWW-Authenticate",
         String.Format("Basic realm=\"{0}\"", "myname.mycompany.com"));
  }
  </code></pre>
  
  <p>The site is assigned an SSL certicicate created with makecert utility and is "issued" to "myname.mycompany.com". The caller creates a request:</p>
  
  <pre><code>HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create( serverUrl );
  CredentialCache cache = new CredentialCache();
  cache.Add( new Uri( serverUrl ), "Basic", new NetworkCredential( "UserName", "password" ) );
  request.Credentials = cache;
  </code></pre>
  
  <p>where <code>serverUrl</code> starts with <code>https://</code> and when the request is being processed by the server the server sends the "WWW-Authenticate" reply, then an exception is thrown on the client side with "Unable to write data to the transport connection: An established connection was aborted by the software in your host machine." text.</p>
  
  <p>So clearly there's something wrong at SSL negotiation level and I can't fugure what it is. I guess it could be something dealing with the realm.</p>
  
  <p>My question is - what is a <em>realm</em> and how is it related to the name of the party to which an SSL certificate was issued when a connection is made over SSL?</p>