Click here to Skip to main content
15,894,539 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
after login I have a welcome page

but when I put direct link like localhost://welcome.aspx

I shows me the welcome page which is wrong !

I need to redirect back to the page of login if any one who is not logged with user id and pw

the following code which I Have tried won't let me stay on welcome page even if entered login and pw correctly

What I have tried:

if(!isPostback)
{
response.redirect("home.aspx");
C#


}
Posted
Updated 11-Nov-17 3:41am

1 solution

There are few approaches to do this.
1. Correcting your code.
C#
//if(!isPostback)
if(Session["MySession"]!=null)
{
   response.redirect("home.aspx");
}

Do not wrap this in the postback check as you'll be needing this for both the conditions i.e, on first load and postbacks. Think about a scenario when you are logged in to the application and are idle for few hours and then you are clicking one button in the page then you wouldn't be expecting your code to do it's stuff as session will already be expired.

2. using Global.aspx
Check following link for further details-
Redirect Page After Session Time Out in ASP.Net[^]

Hope, it helps :)
 
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