Click here to Skip to main content
15,896,915 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi frndz....I have a requirement to redirect a user to last visited page when log in again .... Plz help me...thnkz in advance
Posted
Updated 18-Oct-13 19:56pm
v3

C#
protected void btnSubmit_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["dbconnection"].ConnectionString);
con.Open();
SqlCommand cmd = new SqlCommand("select * from UserInformation where UserName =@username and Password=@password",con);
cmd.Parameters.AddWithValue("@username", txtUserName.Text);
cmd.Parameters.AddWithValue("@password", txtPWD.Text);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
if(dt.Rows.Count>0)
{
Response.Redirect("Details.aspx");
}
else
{
ClientScript.RegisterStartupScript(Page.GetType(), "validation", "<script language='javascript'>alert('Invalid Username and Password')</script>");
}
}
 
Share this answer
 
put code in webconfig ....

put rewriter tag
rewrite url="~/Login.aspx/(.+)" to="~/Login.aspx?rurl=$1"/ and write this sentance

take one (i have comman class) class. and put this code in class.....

public static string Login(string rurl)
{
string url = "";
if (rurl == "")
{
url = GetMainUrl() + "Login.aspx";
}
else
{
if (rurl.StartsWith("/"))
{
url = GetMainUrl() + "Login.aspx" + rurl;
}
else
url = GetMainUrl() + "Login.aspx" + "/" + rurl;
}
return url;
}

now every page put this code when session expire....

if (session["memberLogin"] != null)
{
}
else
{
Response.Redirect(Common.Login(Request.RawUrl));
//Cooman mean i have comman class which are above in code
}


and take one dll in bin folder urlrewrtier in and the do ......
 
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