How To check Session Redirect like this

Posted by Jayakumars under ASP.NET on 5/26/2011 | Points: 10 | Views : 2285 | Status : [Member] [MVP] | Replies : 7
Hi
every one
I have 10 aspx page every page i am validate username from session every page I wrote this functionality i need any thing simple way do this functionality and without
write every page any one post here .

Thanks to all

Mark as Answer if its helpful to you


Responses

Posted by: Ndebata on: 5/26/2011 [Member] Starter | Points: 25

Up
0
Down
Hi
Just add a Class ( Lets say MyPageBase to App_Code) Which will be inheritted from System.Web.UI.Page
public class MyPageBase : System.Web.UI.Page

{
//Try to handle what you are doing in each page here.
protected override void OnInit(EventArgs e)
{
}
protected override void OnLoad(EventArgs e)
{
}

}


Then in all aspx page(10 Pages for you ) just simple inherit them from MyPageBase instead of System.Web.UI.Page
And you are done :)

Thanks,
Debata

Jayakumars, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 5/26/2011 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
If you are using asp.net the you should look at Masterpages , so that you can check the session from the MasterPage.

Thank you for posting at Dotnetfunda
[Administrator]

Jayakumars, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jayakumars on: 5/26/2011 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi

Ndebata
can you post sample applicartion.

Mark as Answer if its helpful to you

Jayakumars, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jayakumars on: 5/26/2011 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi
webmaster Vuyiswamb

can you explain Clearly.

Mark as Answer if its helpful to you

Jayakumars, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ndebata on: 5/27/2011 [Member] Starter | Points: 25

Up
0
Down
Hi
Please find the attached code.
If you run any page either Page1 or Page2 before click on login, (i.e. UserName is not there in Session) it will redirect you to Login.aspx page in the sample.

Thanks,
Debata
 Download source file

Jayakumars, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jayakumars on: 5/27/2011 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi

thanks a lot Ndebata another one can you send timeout session period 30 like a gmail account suppose my aspx no response 1 min that page
i will come after 1 min access that page i need expire session and goto login pages in my mail id

this is my mail id : kumaraspcode2009@gmail.com


Mark as Answer if its helpful to you

Jayakumars, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Prabhakar on: 5/27/2011 [Member] [MVP] Starter | Points: 25

Up
0
Down
hi jayakumars .

i think u use Timer_tick Event and expire ur session and go to Login Page . .


Write this code on Timer_Tick Event . .

Response.Expires = -1;

Response.ExpiresAbsolute = DateTime.Now.AddDays(-1);
Response.CacheControl = "no-cache";

Response.AddHeader("Pragma", "no-cache");
string[] cooki = Request.Cookies.AllKeys;

for (int ck = 0; ck < cooki.Length; ck++)
{
Response.Cookies[cooki[ck]].Expires = DateTime.Now.AddDays(-1);
}
Session.Abandon();

Response.Redirect("~/Login.aspx?msg=You Have Successfully Logged Out");


Best Regard's
Prabhakar

Jayakumars, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response