登录后重定向不起作用 [英] Redirection after loggin in not working
本文介绍了登录后重定向不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
HEllo everyone,
我在登录过程中遇到redirecton问题。我正在尝试此代码
HEllo everyone,
I have a problem with the redirecton after a seccesful login. I am trying this code
private void imgBtnLogin_Click(object sender, ImageClickEventArgs e)
{
FormsAuthentication.Initialize();
SqlConnection con = new SqlConnection("data source=.; initial catalog = AxaStock; integrated security = true");
SqlCommand cmd = con.CreateCommand();
cmd.CommandText = "select r.nomRole from Collaborateur c, Role r where r.idRole=c.idRole and matricule=@matricule and password=@password";
cmd.Parameters.Add("@matricule", SqlDbType.VarChar, 64).Value = txtLogin.Text;
cmd.Parameters.Add("@password", SqlDbType.VarChar, 128).Value = txtPassword.Text;
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
if (reader.Read())
{
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, txtLogin.Text,
DateTime.Now,
DateTime.Now.AddMinutes(30),
true,
reader.GetString(0),
FormsAuthentication.FormsCookiePath);
string hash = FormsAuthentication.Encrypt(ticket);
HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, hash);
if (ticket.IsPersistent) cookie.Expires = ticket.Expiration;
Response.Cookies.Add(cookie);
string returnUrl = Request.QueryString["ReturnUrl"];
if (returnUrl == null)
{
returnUrl = "/";
}
}
else
{
lblError.Text = "Matricule / mot de passe incorrect. Réssayez !";
lblError.Visible = true;
}
reader.Close();
con.Close();
}
当我点击按钮登录时,它不会重定向我到特定文件夹,它停留在登录页面,没有给我任何消息。我怎么能告诉他将我重定向到Accueil.aspx?
请帮助
When I click the button login, it doesnt redirect me to the specific folder, it Stays in the Login page without giving me any message. How can I tell him to redirect me to the Accueil.aspx ??
please help
推荐答案
成功登录后请使用以下代码进行重定向。
Please use below code for redirection,after successfull login.
Response.Redirect("...page path.../Accueil.aspx");
你必须使用Response.Redirect()
,在您的方法结束时,如下一个示例所示:
You have to useResponse.Redirect()
, at the end of your method, like in the next example:
Response.Redirect("Accueil.aspx");
您好,
1. returnUrl应该是您登录后的登陆页面(尝试'/welcome.aspx'而不是'/')
2. Response.Redirect(returnUrl);
reader.Close() ;
con.Close();
Hi,
1. returnUrl should be the landing page after your login (try '/welcome.aspx' instead of '/')
2. Response.Redirect(returnUrl);
reader.Close();
con.Close();
这篇关于登录后重定向不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文