Click here to Skip to main content
15,883,705 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Friends,

I have developed an asp .net application,There are two type of users patient and doctor. Login pages are different for the users but after login pages are same for both some controls are enabled and disabled based on the type of user.
I need to logout and redirect to the respective login page on session timeout.

Currently i'm doing like this,

C#
public class PageBase : System.Web.UI.Page
{
    public PageBase()
    {
        //
        // TODO: Add constructor logic here
        //
    }

    protected override void OnPreRender(EventArgs e)
    {

        base.OnPreRender(e);
        if(string.IsNullOrEmpty(Convert.ToString(Session["USERID"])))
            Response.Redirect(ConfigurationManager.AppSettings["InternalUrl"].ToString());

    }

}



Please have a look at the above code.
i'm redirecting the user to login page based on the session null or empty. But here i need to find the type of user, so that i can give the redirect URL.
Posted
Updated 9-Mar-14 22:25pm
v2

1 solution

It's pretty simple. :)
On Login Button Click, Store the type of user as well in the Session. As you've said that Login pages are different for both the users, then it won't be an issue. For example,

If Doctor is logging in, on button click of login,
Session["UserType"] = "doc";

And on the other page, do something like following,
C#
protected override void OnPreRender(EventArgs e)
{
    base.OnPreRender(e);
    if(string.IsNullOrEmpty(Convert.ToString(Session["USERID"])))
        Response.Redirect(ConfigurationManager.AppSettings["InternalUrl"].ToString());

    if(string.IsNullOrEmpty(Convert.ToString(Session["UserType"])))
        Reponse.Redirect("SomePage.aspx");
}

-KR
 
Share this answer
 
Comments
Rockstar_ 10-Mar-14 6:19am    
But the this onPrerender executes after the content page load know?
Rockstar_ 10-Mar-14 7:09am    
Here the session type can be "doc" or "patient".
when the session is expired. How can we check for whether it is "doc" or "patient".
Rockstar_ 10-Mar-14 7:29am    
What about for postbacks?
Krunal Rohit 10-Mar-14 9:54am    
Once the values in Session, you don't have to worry about postbacks.
And about onPreRender, I forgot to mention that use onPreInit() method of Page class.

-KR

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