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 7846761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:41:45+00:00 2026-06-02T17:41:45+00:00

I have a website with ASP.NET Forms Authentication. I recently implement to save cookie

  • 0

I have a website with ASP.NET Forms Authentication. I recently implement to save cookie upon user login and now I found a problem. I am not 100% if the problem persist before or not.

The steps to reproduce are:

  1. go to my website with www (www.mysite.com)
  2. Login to the website.
  3. go to the website without www (mysite.com)
  4. It would ask me to login again so I did.
  5. Logout of the website. it redirect me to Login page.
  6. type http://www.mysite.com in the address bar and I found it still login.

So accessing to my website with or without (www) become like accessing to two different website. Logging out from http://www.mysite.com does not logout from mysite.com. The same with logging in, and vice versa.

Login page

    Login1_Authenticate Handles Login1.Authenticate

     Dim result As Boolean = UserLogin(userName, password)
     If (result) Then
        e.Authenticated = True
        If Login1.RememberMeSet = True Then
            SetCookies(userName)
        End If
        LoginCounter(userName)
     Else
        e.Authenticated = False
     End If        

SetCookies()

    Dim tkt As FormsAuthenticationTicket
    Dim cookiestr As String
    Dim ck As HttpCookie

    tkt = New FormsAuthenticationTicket(1, userName, DateTime.Now(), DateTime.Now.AddDays(7), False, "")
    cookiestr = FormsAuthentication.Encrypt(tkt)
    ck = New HttpCookie(FormsAuthentication.FormsCookieName(), cookiestr)
    ck.Expires = tkt.Expiration
    ck.Path = FormsAuthentication.FormsCookiePath()
    HttpContext.Current.Request.Cookies.Remove(".ASPXAUTH")
    Response.Cookies.Add(ck)

    End Sub

Login Status Control on Master Page

    LoginStatus1_LoggingOut Handles LoginStatus1.LoggingOut

    FormsAuthentication.SignOut()
    Session.Clear()
    Session.Abandon()
    Dim cookie1 As New HttpCookie(FormsAuthentication.FormsCookieName, "")
    cookie1.Expires = DateTime.Now.AddYears(-1)
    Response.Cookies.Add(cookie1)

    Dim cookie2 As New HttpCookie("ASP.NET_SessionId", "")
    cookie2.Expires = DateTime.Now.AddYears(-1)
    Response.Cookies.Add(cookie2)

Web.config

    <authorization>
    <deny users="?"/>
    </authorization>

    <authentication mode="Forms">
    <forms name=".ASPXAUTH" loginUrl="Login.aspx" defaultUrl="Default.aspx" cookieless="UseCookies"  timeout="1440" path="/" protection="All"/>
    </authentication>

Solution: put this in Global.asax ..

     Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
     Dim fromurl As String = "http://mysite.com"
     Dim tourl As String = "http://www.mysite.com"
     If HttpContext.Current.Request.Url.ToString().ToLower().Contains(fromurl) Then
        HttpContext.Current.Response.Status = "301 Moved Permanently"
        HttpContext.Current.Response.AddHeader("Location", tourl)
     End If
     End Sub
  • 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-02T17:41:48+00:00Added an answer on June 2, 2026 at 5:41 pm

    I would say the session cookie is (sub)domain specific.

    You need to redirect all requests from one domain to the other to force the browser to only use one session.

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

Sidebar

Related Questions

I'm using Forms authentication in ASP.NET MVC website and I store user account login
I have an ASP.NET website configured with <authentication mode=Forms> <forms loginUrl=Login.aspx timeout=10080> </forms> </authentication>
I have a website that uses basic ASP.Net forms authentication. In the web.config file
I have an existing asp.net mvc website that uses basic forms authentication. The site
I have website that is ASP.NET with Forms Authentication, clicking the logout button does
I have an asp.net website that uses forms authentication. There are a few things
I have an ASP.NET website that uses Forms authentication <authentication mode=Forms> <forms name=NewsCoreAuthentication loginUrl=~/Default.aspx
I have a ASP.NET website deployed under IIS uisng virtual directories. I'm using forms
I am working on an ASP.NET website which uses forms authentication with a custom
I have an ASP.NET website on a WinServer2k8 machine, which is protetced through Forms

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.