asp.net - Forcing .net Login control to make the user logout if a cookie is null -


i have code base web application connected 2 databases. depending on login control user uses login, different database connected code. doing of cookie. cookie in public class called authenticateduser. class looks this:

public class authenticateduser : system.web.ui.page {     public static string connectionstring     {                 {             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();        }          {          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 working on development machine, when tried deploy it, user using "remember me" option on site getting null reference error because did not use login control obtain cookie.

what best method around this? thinking if user logged in authenticateduser class not connectionstring log out user force them use login control again. should do?

try use:

try   {         formsauthentication.signout();   }     {         response.redirect("~/home.aspx");   } 

this way preferable, example if in time decide not- cookie auth, url based - formsauthentication manage gracefully.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -