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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T14:59:55+00:00 2026-05-17T14:59:55+00:00

I have a code base web application that is connected to 2 databases. Depending

  • 0

I have a code base web application that is connected to 2 databases. Depending on which login control a user uses to login, a different database is connected to the code. I am doing all of this by a cookie. This cookie is in a public class called AuthenticatedUser. The class looks like this:

public class AuthenticatedUser : System.Web.UI.Page
{
    public static string ConnectionString
    {
        get
        {
            HttpCookie myCookie = HttpContext.Current.Request.Cookies["connectionString"];
            return GetConnectionStringFromName(myCookie);
        }
        set
        {
            if (HttpContext.Current.Request.Cookies["connectionString"] != null)
            {
                ExpireCookies(HttpContext.Current);
            }
            var allCookies = HttpContext.Current.Request.Cookies.AllKeys;
            HttpCookie cookie = new HttpCookie("connectionString");
            cookie.Value = value;
            cookie.Expires = DateTime.Now.AddYears(100);
            HttpContext.Current.Response.Cookies.Add(cookie);
        }
    }

    private static string GetConnectionStringFromName(HttpCookie myCookie)
{
    try
    {
        string connectionStringName = myCookie.Value;
        return ConfigurationManager.ConnectionStrings[connectionStringName].ConnectionString;
    }
    catch
    {
       FormsAuthentication.SignOut();   
    }
     finally
    {
         HttpContext.Current.Response.Redirect("/default.aspx");
    }
    return "";

}        private static void ExpireCookies(HttpContext current)
    {
        var allCookies = current.Request.Cookies.AllKeys;
        foreach (var cook in allCookies.Select(c => current.Response.Cookies[c]).Where(cook => cook != null))
        {
            cook.Value = "";
            cook.Expires = DateTime.Now.AddDays(-1);
            current.Request.Cookies.Remove(cook.Name);
            cook.Name = "";
        }
    } 
}

This seems to be working on my development machine, but when I tried to deploy it, any user that was using the “remember me” option on the site was getting a null reference error because they did not use the login control to obtain the cookie.

What is the best method to get around this? I was thinking if a user was logged in but the AuthenticatedUser class could not get a Connectionstring to log out the user to force them to use the login control again. What should I do?

  • 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-05-17T14:59:56+00:00Added an answer on May 17, 2026 at 2:59 pm

    Try use:

    try  
    {  
          FormsAuthentication.SignOut();  
    }  
    finally  
    {  
          Response.Redirect("~/Home.aspx");  
    }
    

    This way is preferable, for example if in some time you will decide not- cookie auth, but URL based – the FormsAuthentication will manage it gracefully.

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

Sidebar

Related Questions

I have a code base that has been used as an ASP.Net web application.
I have an existing website that uses the same code base, but is deployed
I have code in the top layer of my .Net web application that I'd
I have a very large code base that contains extensive unit tests (using CppUnit).
I have a server that hosts my Subversion code base. That server is currently
I'm working on a code base in which we have several configurable types. One
I have this legacy code base (Compaq PERL) , about 1500 lines of code,
I have a C code base and need to programmatically identify all of the
I have taken over a large code base and would like to get an
We have a large ASP classic code base but I'm looking to do future

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.