登录后重定向 [英] Redirection after login
本文介绍了登录后重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨frndz ....我需要在再次登录时将用户重定向到上次访问过的页面.... Plz帮我... thnkz提前
解决方案
protected void btnSubmit_Click( object sender,EventArgs e)
{
SqlConnection con = new SqlConnection (ConfigurationManager.ConnectionStrings [ dbconnection]。ConnectionString);
con.Open();
SqlCommand cmd = new SqlCommand( select *来自UserInformation,其中UserName = @ username和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('无效的用户名和密码')< / script>);
}
}
将代码放入webconfig ....
put rewriter tag
rewrite url =〜/ Login.aspx /(.+)to =〜/ Login.aspx?rurl =
1/并写下这个信号
拿一个(我有comman类)课程。并将此代码放在课堂上.....
公共静态字符串登录(字符串rurl)
{
string url =;
if(rurl ==)
{
url = GetMainUrl()+登录。 aspx;
}
else
{
if(rurl.StartsWith(/))< br $>
{
url = GetMainUrl()+Login.aspx+ rurl;
}
else
url = GetMainUrl()+Login.aspx+/+ rurl;
}
返回网址;
}
现在每个页面在会话到期时都会输入此代码....
if( session [memberLogin]!= null)
{
}
else
{
Response.Redirect(Common.Login(Request.RawUrl));
// Cooman意味着我在代码中有上面的comman类< br $>
}
并在bin文件夹urlrewrtier中取一个dll并执行......
Hi frndz....I have a requirement to redirect a user to last visited page when log in again .... Plz help me...thnkz in advance
解决方案
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>"); } }
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 ......
这篇关于登录后重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文