登录后页面错误

时间:2013-03-13 10:06:15

标签: asp.net redirect

如果我点击链接(不登录网站),我将导航到此页面:

http://localhost:59196/Login.aspx?ReturnUrl=%2fTest%2fContacts.aspx

当我登录该网站时,我想重定向到我的主页而不是Test Contacts.aspx页面。 我该如何解决这个问题?

如果我这样做,那么我就没有登录。

protected void Page_Load(object sender, EventArgs e)
    {


    }


    protected void Login1_LoggingIn(object sender, LoginCancelEventArgs e)
    {
        Response.Redirect("Home");
    }

4 个答案:

答案 0 :(得分:1)

只需将您点击的链接网址更改为:

http://localhost:59196/Login.aspx?ReturnUrl=Index.aspx

答案 1 :(得分:1)

我认为您点击了Test Contact.aspx页面而没有登录,因此您已被重定向到Login页面,其查询字符串为ReturnURl = test contact.aspx,可用于从登录页面重定向。

因此,您不必使用return url查询字符串,而是可以从登录页面中的登录按钮单击直接重定向到您的页面页面。 希望它有效。

我的意思是

Loginbutton_click()
{
//login validation code here 
 //after successful validation
Response.redirect("Yyourhomepageurlhere");
}

答案 2 :(得分:0)

您想要重定向到

http://localhost:59196/Login.aspx?ReturnUrl=%2fTest%2fIndex.aspx

而不是

http://localhost:59196/Login.aspx?ReturnUrl=%2fTest%2fContacts.aspx

换句话说,您单击的链接应指向上面的第一个链接而不是第二个链接。

剩下的问题是如何生成链接?它们是硬编码还是您正在使用MVC并以某种方式生成链接?链接是否甚至在您的控件中生成?

看起来您的代码会查看ReturnUrl查询字符串参数,并在成功登录时重定向到它。

您是否从“联系人”页面进入“登录”页面?如果是这样,那么ReturnUrl可能是根据您来自哪里动态生成的。您可能要求将其修复为索引页面(我假设这是您所称的)。但要小心,其他开发人员可能希望此链接是动态的。

答案 3 :(得分:0)

我必须改变这个事件。

protected void Login1_LoggedIn(object sender, EventArgs e)
    {
        Response.Redirect("Home");
    }