Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
3.40/5 (2 votes)
I have login page when admin login and after that he goes to setting and
click on impersonate and dropdown filled with all user and admin under that particular admin who is login.

After select any user from dropdown list the main user will logout and he will login through id of selected user in dropdown list..

I m destrying session of main user and fetching the value of selected user and assign his value to session..bt its nt working..help me and gave me suggesion

C#
public static void LoginUser(string UserName)
       {
           DataSet ObjData = null;
           User ObjUser = null;
           Admin ObjAdmin = null;
           Helpers.SessionHelper ObjSession = null;
           try
           {


               ObjUser = new User();
               ObjAdmin = new Admin();

               ObjAdmin.UserName = UserName;
               ObjData = ObjAdmin.LoginImpersonateUser();
               if (Helpers.SessionHelper.CurrentUserName != "Anonymous")
               {
                   HttpContext.Current.Session.Abandon(); //here killing the main session
                   ObjSession = new Helpers.SessionHelper();
                  ObjSession.StaticProNull();
               }

               foreach (DataRow item in ObjData.Tables[0].Rows) //fetching the values of selected user
               {

                   ObjUser.UserCompany.CompanyID = Convert.ToInt32(item["companyID"]);
                   ObjUser.UserName = item["UserName"].ToString();
                   ObjUser.EmailAddress = item["EmailAddress"].ToString();
                   ObjUser.UserCompany.CompanyName = item["CompanyName"].ToString();
                   ObjUser.UserCompany.IsCompanyEnabled = Convert.ToInt32(item["IsCompanyEnabled"]);
                   ObjUser.IsCompanyAdmin = Convert.ToInt32(item["IsCompanyAdmin"]);
                   ObjUser.ID = Convert.ToInt32(item["UserID"]);
                   ObjUser.FirstName = item["FirstName"].ToString();
                   ObjUser.Surname = item["surname"].ToString();
                   Helpers.AccessHelper.DoLogin(ObjUser);// calling the method to assign values to session variables.
               }


               HttpContext.Current.Response.Redirect("~/DashBoard.aspx", true);

           }
           catch (Exception)
           {

               throw;
           }
           finally
           {


           }


Thanx..
Posted
Updated 12-Mar-12 2:04am
v2

C#
HttpContext.Current.Session.Clear();
// use this instead of Abandon()
 
Share this answer
 
Comments
Sushil Mate 28-Jun-13 6:37am    
OP's reply in the solution, Just pasting here so you can get the notification:
its nt working..coz i have static class ..and how to remove the properties values of static class???
C#
protected void btn_fourthPage_Click(object sender, EventArgs e)
    {
        try
        {
            HttpContext.Current.Session["fourthpage"] = "4";
            Response.Redirect("~/LoginPage.aspx",false);
        }
        catch (Exception ex)
        {
            Response.Write(ex.Message);
        }
    }

can any one explain how 4 is assigned
 
Share this answer
 
v2
Comments
CHill60 28-Jun-13 9:40am    
If this is a query then please posst your own question
Sergey Alexandrovich Kryukov 18-Jul-13 2:00am    
Fake solution. Please don't do such things.
—SA
C#
Session.Remove("name of your session here");
 
Share this answer
 
v2
You can override the sessions, by applying the values of the selected user to the existing sessions.

Thanks,
 
Share this answer
 
Session["newsession"]=Session["killsession"];

Session.Remove("killsession");

Thanks
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900