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

  • SEARCH
  • Home
  • 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 9272761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:56:37+00:00 2026-06-18T15:56:37+00:00

I’m noticing some strange behavior with a shared authentication cookie setup, here’s my scenario.

  • 0

I’m noticing some strange behavior with a shared authentication cookie setup, here’s my scenario.

I’ve got two applications with the domains similar to the following:

login.mydomain.com
system.mydomain.com

I am redirecting the user to login.mydomain.com and dropping a the cookie from there on mydomain.com like so.

system.mydomain.com:

void Application_AuthenticateRequest(object sender, EventArgs e)
    {
        if (Context.User == null || !Request.IsAuthenticated)
        {
            HttpContext.Current.Response.Redirect("http://login.mydomain.com");
        }
    }

login.mydomain.com

protected void btnSubmit_Click(object sender, EventArgs e)
    {
        pnlLoginNotice.Visible = true;
        if (Membership.ValidateUser(txtUsername.Text, txtPassword.Text))
        {
            HttpCookie cookie = FormsAuthentication.GetAuthCookie(txtUsername.Text, chkRememberMe.Checked);
            cookie.Domain = "mydomain.com";

            Response.Cookies.Set(cookie);
        }
    }

Web.config:

<authentication mode="Forms" >
  <forms timeout="2880" name=".COMMONAUTH"  />      
</authentication>

Now the behavior I’m seeing is that I’m finding the .COMMONAUTH cookie dropped under system.mydomain.com sometimes, while there’s the same cookie under mydomain.com. I’ve noticed that it shows up after some time of inactivity on the site.

Is it possible that asp.net is dropping the cookie on it’s own to keep the forms authentication alive?

UPDATE
I’ve tried the following approaches

1:

system.mydomain.com Web.config

<authentication mode="Forms" >
  <forms timeout="1" name=".COMMONAUTH" />      
</authentication>

login.mydomain.com Web.config

<authentication mode="Forms" >
  <forms timeout="2"  name=".COMMONAUTH"/>
</authentication>

When refreshing a page in system.mydomain.com after one minute has passed, I get the .COMMONAUTH cookie under system.mydomain.com

2:

system.mydomain.com Web.config

<authentication mode="Forms" >
  <forms timeout="2" name=".COMMONAUTH"  />      
</authentication>

login.mydomain.com Web.config

<authentication mode="Forms" >
  <forms timeout="1"  name=".COMMONAUTH"/>
</authentication>

When refreshing a page in system.mydomain.com after one minute has passed, I get logged out.

3:

system.mydomain.com Web.config

<authentication mode="Forms" >
  <forms timeout="1" name=".COMMONAUTH" domain="mydomain.com" />      
</authentication>

login.mydomain.com Web.config

<authentication mode="Forms" >
  <forms timeout="2"  name=".COMMONAUTH" domain="mydomain.com"/>
</authentication>

When refreshing a page in system.mydomain.com after one minute has passed, all remains the same and I’m still authenticated. Not sure what will happen when a 3rd application will be introduced to this setup

Conclusion

I think my issue is comming from not setting the domain in the web.config, so system.mydomain.com is trying to refresh the cookie but is using its own domain since I am not telling it where it should be doing it.

My problem is that these applications will have different domain bindings and they will be hosted once for multiple clients. I cannot set FormsAuthentication.CookieDomain as it is read only.

Should I go with option 2, and give my cookie issuer a lower timeout from the other applications? Will this have any implications?

  • 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. Editorial Team
    Editorial Team
    2026-06-18T15:56:38+00:00Added an answer on June 18, 2026 at 3:56 pm

    I ended up doing this, I won’t mark this as the answer just yet, jut in case anyone points out any issues with it.

    In Global.asax

    void Application_AuthenticateRequest(object sender, EventArgs e)
        {
            if (Context.User == null || !Request.IsAuthenticated)
            {
                HttpContext.Current.Response.Redirect(GetLoginUrl());
            }
            else if (Context.User.Identity is FormsIdentity)
            {
                HttpCookie cookie = Context.Request.Cookies[FormsAuthentication.FormsCookieName];
    
                if (cookie != null)
                {
                    FormsAuthenticationTicket currentTicket = FormsAuthentication.Decrypt(cookie.Value);
    
    
                    if (currentTicket == null && currentTicket.Expired)
                    {
                        return;
                    }
                    FormsAuthenticationTicket newTicket = currentTicket;
                    if (FormsAuthentication.SlidingExpiration)
                    {
                        FormsIdentity id = (FormsIdentity)Context.User.Identity;
                        newTicket = FormsAuthentication.RenewTicketIfOld(id.Ticket);
                    }
    
                    if (currentTicket != newTicket)
                    {
                        cookie.Value = FormsAuthentication.Encrypt(newTicket);
                        cookie.Expires = newTicket.Expiration;
                        cookie.Domain = WebGlobal.GetCurrentContextDomain();
    
                        Response.Cookies.Set(cookie);
                    }
                }
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I've tracked down a weird MySQL problem to the two different ways I was
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
i got an object with contents of html markup in it, for example: string
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all

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.