Click here to Skip to main content
15,892,697 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
i have one query about

i created one application in asp.net(C#)with two webforms login.aspx and home page.aspx and i run this application into browser.When i successfully login then it i will direct to Home page and showing welcome Username(By using Session). whenever i copy the url and paste it into another tab of that browser the same homepage is shown but my requirmnet is it should be redirected login page instead of Home pAge.

So please suggest How to handle the session in this case !!!!
Posted

It doesn't work that way - the login info is normally saved in the Cookies which are stored on the client PC - so if he opens a new window without logging out or closing his browser then he remains logged in.

You would either have to store the login in the Sesssion and check it from there (which is unique to the browser tab) or add and check the session ID when you do teh login check. Boith of these will probably mean implementing a custom Membership Provider - which isn't too difficult if (as I assume) you are using Membership already. MSDN can help: http://msdn.microsoft.com/en-us/library/f1kyba5e(v=vs.100).aspx[^]
 
Share this answer
 
Hope this will help you..

C#
protected void Page_Load(object sender, EventArgs e)
 {
     if (!this.IsPostBack)
     {
         if (Request.UrlReferrer == null)
         {
             Session.Abandon();
             Response.Redirect("login.aspx");
         }
     }
 }


If you copy paste the url in another tab means there is no previous page. So if no previous page reference this code will redirect to login page.
..
 
Share this answer
 
Comments
vinodkumarnie 15-Feb-13 4:26am    
You put this in your home page..
Reshma89 15-Feb-13 4:43am    
Thank u so much......
vinodkumarnie 15-Feb-13 4:54am    
Welcome.. Please rate the answers.. It will help us.. Thank u..
Reshma89 15-Feb-13 8:32am    
hii
one more query related to this
when i successfully login it should redirect to home.aspx then i copied the home page url then go to back by using back option of the browser then it should redirect to login page then i paste it homepage url what i copied as before that contains previous page then this code got failed ....
plz suggest what i can do
vinodkumarnie 15-Feb-13 22:41pm    
after copy paste what you want to do..? how it should work..?
this can be done by the session
if the user's authentication is right in login page then you can match session at home page.
i will give you example if right login at login page then pass session

C#
 Session["user"] = txtuser.Text;
Response.Redirect("adminhome.aspx");


and in home page check the user authentication

C#
Labeluser.Text = Session["user"].ToString();
                str = "select * from login where username='" + Labeluser.Text + "'";
                cmd = new OleDbCommand(str, Classcon.con);
                dtp = new OleDbDataAdapter(cmd);
                ds = new DataSet();
                dtp.Fill(ds);
                if (ds.Tables[0].Rows.Count == 0)
                {
                    Response.Redirect("loginpage.aspx");
                }
                else
                {
                    // Response.Redirect("adminhome.aspx");
                }
 
Share this answer
 
v2

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