Click here to Skip to main content
15,919,358 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:


i have the code in login page(login.aspx.cs) as follows
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class login : System.Web.UI.Page
{
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (txtusername.Text == "ravi" && txtpassword.Text == "reddy")
        {
            Session["PassWord"] = txtpassword.Text;
            Session.Timeout = 1;



            Response.Redirect("checkpassword.aspx");
        }
        else
            Response.Write("wrong details");
    }
}



and and i have the code in password.aspx.cs

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class checkpassword : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        if (Session["PassWord"] == null)
        {

            Response.Redirect("login.aspx");
        }
        else

            lblstatus.Text = Session["PassWord"].ToString();

    }

}



we want the output as after i login into the loginpage it shows reddy as a lable in password.aspx(it is open in browser) after one mintute time i refresh the page the output was sorry session over . i need this what i do and at the same time it redirect to login.aspx page plz help
Posted
Comments
Varun Sareen 17-Feb-12 7:02am    
why are you doing Session.TimeOut=1 after setting it in login.aspx page??why are you doing Session.TimeOut=1 after setting it in login.aspx page??
ZurdoDev 17-Feb-12 7:53am    
Not sure exactly what you want? Are you wanting the page to automatically go to the login page when the session has timed out? You need a client side (JS) solution for that.
amolpatil2243 17-Feb-12 9:46am    
hi
set session.timeout in web config.

1 solution

Don't use manual authentication in ASP.net unless you have a really good reason to. Look at the Membership and Roles features and use them.

If you want to check for session expiry and auto-redirect then you need a little AJAX script that calls a server-side script that looks something like
Response.Write(null == Session["PassWord"] ? "expired" : "valid");

... and then checks the result and redirects to a login page if necessary.
 
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