繁体   English   中英

如何将特定的 URL 重定向到 ASP.NET 中的另一个 URL?

[英]How to redirect a specific URL to another URL in ASP.NET?

是否可以将特定的 URL 重定向到另一个页面?

假设用户通过单击此链接/url 接收到一个链接,例如(mywebsite.com/ConfirmEmail.aspx?with-some-token/code),它只进入一次确认页面(mywebsite/ConfirmEmail.aspx)和确认页面必须使用包含令牌和/或代码的 url 打开一次,如果单击/打开 url (mywebsite.com/ConfirmEmail.aspx?with-some-token/code),则第二次打开它会重定向到主页。

我的问题在这里......如果我从 URL 中删除令牌或代码,它仍然会进入不允许的确认页面。 现在我只想将不包含令牌和/或代码的 url mywebsite.com/ConfirmEmail.aspx 重定向到主页(index.aspx)。

这是我的代码:

protected void Page_Load(object sender, EventArgs e)
    {
        try
        {

                if (Request.QueryString["Code"] != null)
                {
                    string id = Request.QueryString["Code"].ToString().Replace(";domain;", "=").Replace(' ', '+');
                    string un = Request.QueryString["un"].ToString().Replace(";domain;", "=").Replace(' ', '+');
                    string emailID = ED.EncryptDycrpt.DecryptString(id, "tokencode");
                    string UserName = ED.EncryptDycrpt.DecryptString(un, "tokencode");
                    lblUserName.Text = UserName;
                    DataTable dt = objBlUser.sp_selectConfirmUserByEmail(emailID);
                    if (dt.Rows.Count > 0)
                    {
                        Response.Redirect("index.aspx");
                    }
                    int rec = objBlUser.Jobs_ConfirmUserEmail(emailID);
                    if (rec > 0)
                    {
                        //Label1.Text = "user confirmed";
                        //send email
                        Sendemail(emailID, UserName);
                    }
                    else
                        Response.Redirect("index.aspx");
                }
            }

        catch (Exception exe)
        {

            Response.Redirect("index.aspx");
        }  
    }

将令牌添加到 session。 喜欢

Session["Token"] = token;

当页面打开时,如果 session["token"] 然后重定向,否则执行你的代码。

如果用户离开站点,Session 将清除。

解决方法在这里!!!

protected void Page_Load(object sender, EventArgs e)
    {
        try
        {

                if (Request.QueryString["Code"] != null)
                {
                    string id = Request.QueryString["Code"].ToString().Replace(";domain;", "=").Replace(' ', '+');
                    string un = Request.QueryString["un"].ToString().Replace(";domain;", "=").Replace(' ', '+');
                    string emailID = ED.EncryptDycrpt.DecryptString(id, "tokencode");
                    string UserName = ED.EncryptDycrpt.DecryptString(un, "tokencode");
                    lblUserName.Text = UserName;
                    DataTable dt = objBlUser.sp_selectConfirmUserByEmail(emailID);
                    if (dt.Rows.Count > 0)
                    {
                        Response.Redirect("index.aspx");
                    }
                    int rec = objBlUser.Jobs_ConfirmUserEmail(emailID);
                    if (rec > 0)
                    {
                        //Label1.Text = "user confirmed";
                        //send email
                        Sendemail(emailID, UserName);
                    }
                    else
                        Response.Redirect("index.aspx");
                }
             else
                  {
                        Response.Redirect("index.aspx");
                  }
            }

        catch (Exception exe)
        {

            Response.Redirect("index.aspx");
        }  
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM