如何在登录到同一页面后重定向会员他/她正在上网 [英] How to redirect member after login to same page s/he was surfing

查看:60
本文介绍了如何在登录到同一页面后重定向会员他/她正在上网的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在登录之后将会员重定向到他正在浏览的上一页...

我试过但没有工作...有人能让我知道如何做到这一点..



我试过的代码...



how to redirect a member after login to the previous page he was surfing...
I tried but not working...can someone get me an idea how to do this..

The code i tried...

if (Request.Params["ReturnUrl"] != null)
{
    string abc = Request.Params["ReturnUrl"].ToString();
    FormsAuthentication.RedirectFromLoginPage(txtmail.Text.Trim(), false);

}
else
{
    FormsAuthentication.SetAuthCookie(txtmail.Text.Trim(), false);

    Response.Redirect("Default.aspx");
}
FormsAuthentication.RedirectFromLoginPage(txtmail.Text.Trim(), false);

推荐答案

将以下代码添加到您的配置文件中。(示例代码了解如何实现此类事项)



Add below code to your configuration file.(Sample code to have idea how to implement such things)

<system.web>
  <authentication mode="Forms">
    <forms loginUrl="logon.aspx" name=".ASPXFORMSAUTH">
    </forms>
  </authentication>
  <authorization>
    <deny users="?" />
  </authorization>
</system.web>





实现类似:





Implement something like:

void Logon_Click(object sender, EventArgs e)
  {
    if ((UserEmail.Text == "xyz@domain.com") &&
            (UserPass.Text == "12345"))
      {
          FormsAuthentication.RedirectFromLoginPage
             (UserEmail.Text, Persist.Checked);
      }
      else
      {
          Msg.Text = "Invalid credentials. Please try again.";
      }
  }





当任何未经身份验证的用户尝试打开任何页面时,她将自动重定向到登录她提供了正确的用户名和密码,然后她将被重定向到她之前请求的页面。



快乐编码..:笑:



When any unauthenticated user tries to open any page,she will be automatically redirected to logon page.Once she provides correct username and password,then she will be redirected to the page she was requesting previously.

Happy coding.. :laugh:


我在用户会话超时时使用此方法

i use this method when user session time out
protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

            if (Session["user"] != null)
            {
                
            }
            else
            {
                Response.Redirect("login.aspx?p=" + Request.RawUrl);
            }
        }
    }



成功登录后此方法




and this method after successful login

protected void butUserLogin_Click(object sender, EventArgs e)
    {
            Session["user"] = txtUserName.Text;
            if (Request.QueryString["p"] != null)
            {
                Response.Redirect(Request.QueryString["p"].ToString());
            }
       

    }





这可以帮助你



may this help you


这篇关于如何在登录到同一页面后重定向会员他/她正在上网的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆