I just want simple login and after session expire supoose after 1 min the page will redirect automatically to login page and asking for sign in again.
At the time of successfull login create a session and pass a unique value to the session.and on other pages pageload check the same session whether its null or empty or not.If its not null then user is currently logged in so let them access the page else
redirect them to login page and destrory the sessions.
Assign unique key to session:
Session["user"]=Convert.ToString(Guid.NewGuid());
Check the session after successful login on other pages pageload.
if(Session["user"] != null || Session["user"] != string.Empty)
{
// let him access the page
}
else
{
//clear the cache and redirect back to login page.
Response.Redirect("LoginPage.aspx");
}
actually i have stored user name in session ...because user name is redirected to net page with welcome user name status.
This is good .. you can proceed like this.
sanjlaxmi
so i need to store unique key in differnt session?
Yes.For each session there should be a unique key or value that differentiate that user from other apart from your username session.so check both the sessions in every page load.A better approach would be using forms authentication.
SqlCommand cm =new SqlCommand("Select * FROM login WHERE name=@name and password=@password",cn);
cm.Parameters.Add("@name", SqlDbType.VarChar).Value = name;
cm.Parameters.Add("@password", SqlDbType.VarChar).Value = password;
Forget the idea of redirecting when the session times out, the web doesn't support that kind of feature. My session might have timed out because I'm viewing a different site or I've shut my pc down. It's possible but a) very annoying for users as they
might want to keep your page in their browser to view it at their leisure b) involves a semi-advanced solution.
sessionstateSessionTimeOutasp.net
I'm afraid I no longer use this forum due to the new point allocation system.
the page will not automatically redirect back to login page.you have to make a refresh or postback to hit it server then only you will be able to see the changes.just make sure you have session timeout set in web.config for this.
Member
5 Points
16 Posts
session expire after some time and redirect to login page
Mar 28, 2014 04:40 AM|sanjlaxmi|LINK
hi all,
I searched on google,have so many examples.
I tried different ways to implement session in login page but not getting the expecting result.
I just want simple login and after session expire supoose after 1 min the page will redirect automatically to login page and asking for sign in again.
hope i will get the solution...
pls try to give answer.
thanks in advance.
sessionstate SessionTimeOut asp.net
All-Star
15186 Points
3888 Posts
Re: session expire after some time and redirect to login page
Mar 28, 2014 04:50 AM|raju dasa|LINK
Hi,
You can try with refresh meta tag, where content= session timeout in seconds.
Check this site for info:
http://www.metatags.info/meta_http_equiv_refresh
sessionstate SessionTimeOut asp.net
rajudasa.blogspot.com || rajudasa-tech
Star
13653 Points
5480 Posts
Re: session expire after some time and redirect to login page
Mar 28, 2014 10:43 PM|Ashim Chatterjee|LINK
Hello,
To set session timeout you can set it from web.config.
At the time of successfull login create a session and pass a unique value to the session.and on other pages pageload check the same session whether its null or empty or not.If its not null then user is currently logged in so let them access the page else redirect them to login page and destrory the sessions.
Assign unique key to session:
Check the session after successful login on other pages pageload.
Hope It Helped. :)
sessionstate SessionTimeOut asp.net
All-Star
50841 Points
9895 Posts
Re: session expire after some time and redirect to login page
Mar 29, 2014 12:18 AM|A2H|LINK
Hi,
You can also check the solutions provided in below link
sessionstate SessionTimeOut asp.net
Aje
My Blog | Dotnet Funda
Member
5 Points
16 Posts
Re: session expire after some time and redirect to login page
Apr 03, 2014 05:05 AM|sanjlaxmi|LINK
@Ashim Chatte...
actually i have stored user name in session ...because user name is redirected to net page with welcome user name status.
so i need to store unique key in differnt session?
can you pls explain?
pls let me know.
thanks in advance
sessionstate SessionTimeOut asp.net
Star
13653 Points
5480 Posts
Re: session expire after some time and redirect to login page
Apr 03, 2014 05:45 AM|Ashim Chatterjee|LINK
This is good .. you can proceed like this.
Yes.For each session there should be a unique key or value that differentiate that user from other apart from your username session.so check both the sessions in every page load.A better approach would be using forms authentication.
sessionstate SessionTimeOut asp.net
Member
5 Points
16 Posts
Re: session expire after some time and redirect to login page
Apr 03, 2014 11:37 PM|sanjlaxmi|LINK
hi @Ashim Chatte...
thanks for reply..
i have tried all things ..check below code
this is my code in login.aspx page
SqlConnection cn=new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\test.mdf;Integrated Security=True;User Instance=True");
cn.Open();
string name = txtname.Text;
string password=txtPasswd.Text;
Session["test"] = name.ToString();
Session["user"] = Convert.ToString(Guid.NewGuid());
SqlCommand cm =new SqlCommand("Select * FROM login WHERE name=@name and password=@password",cn);
cm.Parameters.Add("@name", SqlDbType.VarChar).Value = name;
cm.Parameters.Add("@password", SqlDbType.VarChar).Value = password;
SqlDataReader reader = cm.ExecuteReader();
if (reader.Read())
{
Response.Redirect("welcome.aspx");
}
else
{
Response.Write("login failed");
}
cn.Close();
//this is welcome.aspx page
protected void Page_Load(object sender, EventArgs e)
{
lblName.Text = "Welcome " +Session["test"].ToString();
//if (Session["test"] == null)
//{
// Response.Redirect("login.aspx");
//}
// ur code added
if (Session["user"] != null || Session["user"] != string.Empty)
{
}
else
{
//clear the cache and redirect back to login page.
Session.Abandon();
Response.Redirect("login.aspx");
}
}
//in web.config page
<sessionState timeout="1" mode="InProc" cookieless="false">
</sessionState>
you mentioned i need to clear the cache..can you tell me how to do that?
is it possible to give you complete code?
i have tried all possible things but still not able to do it.
its a simple two page code but i dont know what things are missing...i googled also so much
pls try to help me out....thanks in advance
sessionstate SessionTimeOut asp.net
Star
13653 Points
5480 Posts
Re: session expire after some time and redirect to login page
Apr 04, 2014 12:01 AM|Ashim Chatterjee|LINK
sure ... :) .. i made some minor changes for better performance , hope you wont mind. :) try below:
LOGIN PAGE:
WELCOME PAGE:
WEB.CONFIG:
sessionstate SessionTimeOut asp.net
Member
5 Points
16 Posts
Re: session expire after some time and redirect to login page
Apr 04, 2014 01:46 AM|sanjlaxmi|LINK
hi @Ashim Chatte...
i tried the same code as it here, but still it not works...
page is not redirecting after 1 min to login page...
is anything missing?
i have set session timeout property as well properly..
i am just trying from 2-3 days but cant find out the answer.
hope i will get solution
sessionstate SessionTimeOut asp.net
Star
13653 Points
5480 Posts
Re: session expire after some time and redirect to login page
Apr 04, 2014 05:47 AM|Ashim Chatterjee|LINK
put a breakpoint in welcome page page load and see if its going to welcome page pageload or not ?
sessionstate SessionTimeOut asp.net
All-Star
37441 Points
9076 Posts
Re: session expire after some time and redirect to login page
Apr 04, 2014 06:07 AM|AidyF|LINK
Look at the code on this link
http://forums.asp.net/t/1888678.aspx?Redirect+do+wanted+URL+after+session+expiration
Forget the idea of redirecting when the session times out, the web doesn't support that kind of feature. My session might have timed out because I'm viewing a different site or I've shut my pc down. It's possible but a) very annoying for users as they might want to keep your page in their browser to view it at their leisure b) involves a semi-advanced solution.
sessionstate SessionTimeOut asp.net
Member
5 Points
16 Posts
Re: session expire after some time and redirect to login page
Apr 07, 2014 02:58 AM|sanjlaxmi|LINK
@Ashim Chatte...
no its not going to welocme page load...wh shld i do?
sessionstate SessionTimeOut asp.net
Star
13653 Points
5480 Posts
Re: session expire after some time and redirect to login page
Apr 07, 2014 03:16 AM|Ashim Chatterjee|LINK
post your current code.
sessionstate SessionTimeOut asp.net
Member
5 Points
16 Posts
Re: session expire after some time and redirect to login page
Apr 07, 2014 05:26 AM|sanjlaxmi|LINK
@Ashim Chatte...
i have written same code as u made changes in it...
thanks in advance
sessionstate SessionTimeOut asp.net
Star
13653 Points
5480 Posts
Re: session expire after some time and redirect to login page
Apr 07, 2014 05:33 AM|Ashim Chatterjee|LINK
what is the problem you are facing now ? its not redirecting to welcome page or any error ??? are you using any authorization schemes here ?
sessionstate SessionTimeOut asp.net
Member
5 Points
16 Posts
Re: session expire after some time and redirect to login page
Apr 07, 2014 09:38 PM|sanjlaxmi|LINK
@Ashim Chatte...
no there is not any error..page is also redirecting welcome page properly but i want after 1 min page automatically redirected to login page again
since i kept session timeout 1 min...but its not redirecting
thanks in advance
sessionstate SessionTimeOut asp.net
Star
13653 Points
5480 Posts
Re: session expire after some time and redirect to login page
Apr 07, 2014 11:31 PM|Ashim Chatterjee|LINK
the page will not automatically redirect back to login page.you have to make a refresh or postback to hit it server then only you will be able to see the changes.just make sure you have session timeout set in web.config for this.
sessionstate SessionTimeOut asp.net
Member
5 Points
16 Posts
Re: session expire after some time and redirect to login page
Apr 08, 2014 01:11 AM|sanjlaxmi|LINK
@Ashim Chatte...
ok...it clears my doubt...
thanks for ur reply...
sessionstate SessionTimeOut asp.net
Star
13653 Points
5480 Posts
Re: session expire after some time and redirect to login page
Apr 08, 2014 01:16 AM|Ashim Chatterjee|LINK
glad to be able to help.
.. happy coding.
sessionstate SessionTimeOut asp.net