Click here to Skip to main content
15,898,134 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All,

I have 3 users on my site and each one of them when sign out it redirects to a different page.

how can i handle this when session time out???

Example:

Factory User:
* Stores credentials in session["FactoryInfo"];
* redirects to login.aspx

Admin User:
* Stores its credentials in session["AdminUser"];
* redirects to adminlogin.aspx

Normal User:
* Stores its credentials in session["NormalUser"];
* redirects to homelogin.aspx

No if user presses on logout link it redirects each user to its login page based on its session variable.

C#
if (Session["FactoryInfo"] != null)//Factory User
{
    Session.Clear();
    Response.Redirect("login.aspx");
}
else if (Session["AdminUser"] != null)//Admin User
{                
    Session.Clear();
    Response.Redirect("adminlogin.aspx");
}
else if(Session["NormalUser"] != null)//Normal User
{
    Session.Clear();
    Response.Redirect("homelogin.aspx");
}


Now if the session times out, then all session variables are NULL!!
so how can i detect the current user and redirects to its specific login page?!!!
Posted

1 solution

... i have a temporary solution . keep a hidden field or label on the master page .. and print the usertype when u logged in . and u will find the solution .

whenever session will timed out .. check the label text and find the usertype
.. and redirect to the desirable page . when logout .
 
Share this answer
 
Comments
_ProgProg_ 27-Dec-15 15:36pm    
Actually i did that solution but i faced a problem.
I am setting the hiddenfield when the user login to the system with its type but it didn't keep the value and after it redirects to its page, it looses its value.
Do you have any idea???
Ashutosh shukla207 28-Dec-15 1:17am    
Do the thing like this . i think u are setting the hiddenfield value above the redirection code . im i right? . if yes , then put that below the rediection code . hope u will get the solution .. best of luck .
_ProgProg_ 28-Dec-15 1:21am    
yes i am setting the hiddenfield value before response.redirect but if i did that after response.redirect, this code will be unreachable.
Am i Right??
Ashutosh shukla207 28-Dec-15 1:34am    
set the hiddenfiel value like this on the master page

protected void Page_Load(object sender, EventArgs e)
{

if (!IsPostBack)
{

if (Session["FactoryInfo"] == null || Session["AdminUser"] == null || Session["NormalUser"] == null)
{
//if u will get any of the session time out .. than break to below the code of setting HiddenField value .. it will not reset the hidden field value.
goto switchHere;
}
else
{
if (Session["FactoryInfo"] != null)
HiddenField1.value = Session["FactoryInfo"].tostring();
if (Session["AdminUser"] != null)
HiddenField1.value = Session["AdminUser"].tostring();
if (Session["NormalUser"] != null)
HiddenField1.value = Session["NormalUser"].tostring();

}


switchHere:
if (Session["FactoryInfo"] == null || Session["AdminUser"] == null || Session["NormalUser"] == null)
{
if (HiddenField1.value=="FactoryInfo")//Factory User
{
Session.Clear();
Response.Redirect("login.aspx");
}
else if (HiddenField1.value=="AdminUser")//Admin User
{
Session.Clear();
Response.Redirect("adminlogin.aspx");
}
else if(HiddenField1.value=="NormalUser")//Normal User
{
Session.Clear();
Response.Redirect("homelogin.aspx");
}
}





}
}


and on the logout button ... if session not expired .. then u have to redirect based on session... and if timeout stuck... than u have to redirect based on hiddenfield value
_ProgProg_ 28-Dec-15 1:45am    
I appreciate your answer so much..

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