Click here to Skip to main content
15,889,909 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to redirect current page on login page on session expiration I have tried some code and web config setting but its not working. please help to solve this problem
Posted
Comments
AshishChaudha 20-Dec-12 2:11am    
Could you please share your code??

hi,
you can write below code in your web.config file.

XML
<system.web>
 <authentication mode="Forms">
     <forms loginUrl="login.aspx" timeout="600" protection="All"/>
 </authentication></system.web>


hope this will help you. please mark as solution if help u.

thanks,
kk
 
Share this answer
 
Comments
Samar chougule 20-Dec-12 6:26am    
first thanks for suggestion ,i tried above settings but its not working here actully i have done this with code using Session.IsNewSession property in basepage but i want to achive this through setting in congig file can you please tell me any more changes need to do in config or code or any possible mistake by me?
try this
C#
if(session["userid"]==null)
{
//redirect your page
}
 
Share this answer
 
Try this

C#
 // Code in Master Page code behind..
 protected void Page_Load(object sender, EventArgs e)
 {
   if (Session["User"] == null)
    //redirect your page to login...
   }
}
 
Share this answer
 
For a hint:
1) Create a web user control.
2) Calculate session timeout in milliseconds.
3) Register JavaScript on your page to run after the calculated time.
4) For ex: setTimeout(function(){alert("Redirecting")},3000) will call alert() after 3 seconds.
 
Share this answer
 
Add following code in master page

C#
protected void Page_Init(object sender, EventArgs e)
   {
   if (Session["userid"] + "" == "")
   {
       Response.Write("<script type="\"text/javascript\"">" +
                       "window.parent.location = '" login?loginUrl=' + window.parent.location + '';" +
                               "</script>");
               Response.End();
   }
}
 
Share this answer
 
in web config file write session timeout
and on page load event write
if(Session["session"]==null)
{
Response.Redirect("Login.aspx");
}
 
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