Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 146745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T08:39:29+00:00 2026-05-11T08:39:29+00:00

Bug: I’ve got an ASP.NET web application that occasionally sets identical cookie keys for

  • 0

Bug:

I’ve got an ASP.NET web application that occasionally sets identical cookie keys for ‘.www.mydomain.com’ and ‘www.mydomain.com’. I’m trying to figure out what default cookie domain ASP.NET sets, and how I accidentally coded the site to sometimes prepend a ‘.’ to the cookie domain.

When 2 cookies have the same key and are sent up from the browser, the ASP.NET web application is unable to differentiate between the two because the domain value is not sent in the header. (See my previous question)

Evidence:

I’ve enabled W3C logging on the web server and verified that both cookies are sent from the client. Here’s an example from the log file (paired down for brevity).

80 GET /default.aspx page= 200 0 0 - - - - - +MyCookie2=sessionID=559ddb9b-0f38-4878-bb07-834c2ca9caae;+MyCookie2=sessionID=e13d83cd-eac2-46fc-b39d-01826b91cb2c; 

Possible Factor:

I am using subdomain enabled forms authentication.

Here’s my web.config settings:

<authentication mode='Forms'> <forms domain='mydomain.com' enableCrossAppRedirects='true' loginUrl='/login' requireSSL='false' timeout='5259600' />         </authentication> 

Here’s and example of setting custom cookies:

HttpCookie cookie1 = new HttpCookie('MyCookie1') {HttpOnly = true, Expires = expiration}; logosCookie['email'] = user.Email; logosCookie['keycode'] = user.PasswordHash; logosCookie['version'] = currentCookieVersion; context.Response.Cookies.Remove('cookie1'); context.Response.Cookies.Add(cookie1);  // set FormsAuth cookie manually so we can add the UserId to the ticket UserData var userData = 'UserId=' + user.UserID; FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(2, user.Email, now, expiration, true, userData);  string str = FormsAuthentication.Encrypt(ticket); HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, str)     {         HttpOnly = true,         Path = FormsAuthentication.FormsCookiePath,         Secure = FormsAuthentication.RequireSSL,         Expires = ticket.Expiration     }; if (FormsAuthentication.CookieDomain != null) {     cookie.Domain = FormsAuthentication.CookieDomain; }  context.Response.Cookies.Remove(FormsAuthentication.FormsCookieName); context.Response.Cookies.Add(cookie1 ); 

Here’s another example of setting a cookie.

var cookie2 = new HttpCookie('MyCookie2'); cookie2[CookieSessionIdKey] = Guid.NewGuid(); cookie2.Expires = DateTime.Now.AddYears(10); HttpContext.Current.Response.Cookies.Set(cookie2); 

Undesirable Resolution:

I can manually force the cookie domain to be a specific value, but I’d like to avoid explicitly declaring the domain. I’d prefer to use the default framework behavior and change my use of ASP.NET to avoid prepend the ‘.’ to the cookie domain for custom cookies.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T08:39:29+00:00Added an answer on May 11, 2026 at 8:39 am

    When no domain is explicitly set by the server on the response, the browser is free to assign the cookie domain value. I haven’t figured out exactly what conditions result in the browser setting ‘www.mydomain.com’ vs ‘.mydomain.com’ on a cookie domain when no domain is provided on the response, but it happened.

    I have a feeling it’s a result of explicitly setting the .ASPAUTH cookie domain value to ‘.mydomain.com’ to enable cross subdomain authentication, while leaving other custom cookie domains set to the default (empty string, or ”).

    I’m going to go with the undesired solution, and explicitly set the cookie domain for all custom cookies to avoid browser quirks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 99k
  • Answers 99k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Qt provides a QSyntaxHighlighter that is probably exactly what you… May 11, 2026 at 7:46 pm
  • Editorial Team
    Editorial Team added an answer You should be able to put something together in a… May 11, 2026 at 7:46 pm
  • Editorial Team
    Editorial Team added an answer I pretty much agree with Greg, but here's the regex… May 11, 2026 at 7:46 pm

Related Questions

Bug: I've got an ASP.NET web application that occasionally sets identical cookie keys for
I just introduced a bug into my code because I seem to have misunderstood
Boy do I have a strange bug. I have a website that needs to
So I have been pulling my hair out troubleshooting this bug I have been
i wonder if i've found a compiler bug? i was removing some old code

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.