title: How to get the current domain name in Startup.cs
body: <p>I have a domain that has multiple sites underneath it.</p>
  
  <p>In my <code>Startup.cs</code> I have the following code</p>
  
  <pre><code>public void ConfigureServices(IServiceCollection services)
  {
      services.AddIdentity&lt;ApplicationUser, ApplicationRole&gt;(options =&gt;
      {
          options.Cookies.ApplicationCookie.CookieName = "MyAppName";
          options.Cookies.ApplicationCookie.ExpireTimeSpanTimeSpan.FromMinutes(300);
       })
       .AddEntityFrameworkStores&lt;MyDbContext, Guid&gt;()
       .AddDefaultTokenProviders();
  </code></pre>
  
  <p>On the production machine all my sites are in a subfolder under the same site in <code>IIS</code> so I don't want to use the default domain as the cookie name otherwise different sites cookies will have the same name</p>
  
  <p>What I want is to get the current domain e..g mydomain.com and then append it to an explicit cookiename per site that I specify in <code>Startup.cs</code> e.g. </p>
  
  <pre><code> var domain = "get the server domain here somehow e.g. domain.com";
   ...
   options.Cookies.ApplicationCookie.CookieName = "MyAppName." + domain;
  </code></pre>
  
  <p>How do I do this?</p>
  
  <p>The reason I ask:</p>
  
  <p>I can see in Chrome developer tools the cookies fall under separate domain names of the site I am accessing. However I sometimes somehow still get the situation of when I log into the same site on two different servers, that I can't log into one and it doesn't log any error. The only solution is to use another browser so I can only assume by the symptoms can only be to do with the cookie.</p>
  
  <p>So my question is really just a personal preference question as in my environment I would prefer to append the domain name to the cookie name although the cookie can only belong to a specific domain.</p>