0

我试图让我的网站以 Twitter.com 的方式运行。如果您没有登录,www.twitter.com,打开的第一页是允许访客登录/注册的主页。但是,如果这不是您第一次访问该网站,您将保持登录状态,并且下次访问 www.twitter.com 时,加载的第一个页面是时间线。

从主页页面加载我尝试了以下代码,但我很确定它不正确

protected void Page_Load(object sender, EventArgs e)
{
    if (Login1.LoggedIn == true)
    {
        Response.Redirect("abc.aspx");
    }    
}

LoggedIn 下面有一条红色错误线,上面写着“要评估的表达式”

我该如何纠正这个问题,所以如果用户已经登录,加载的第一页是 abc.aspx

4

2 回答 2

3

尝试检查 HttpContext 。

protected void Page_Load(object sender, EventArgs e)
{
    if (User.Identity.IsAuthenticated)
    {
        Response.Redirect("abc.aspx");
    }    
}

您可以使用上面的代码添加它,以确保它们在实际登录发生时转到 abc.aspx。

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

有关登录控件的更多信息http://forums.asp.net/t/1403132.aspx/1

于 2012-05-17T13:19:20.290 回答
2

如果您正在使用,请Forms Authentication使用defaultUrl="abc.aspx".

web.config 示例

<authentication mode="Forms">
    <forms loginUrl="Login.aspx" defaultUrl="abc.aspx" />
</authentication>

有关详细信息,请参阅用于身份验证的表单元素(ASP.NET 设置架构)

于 2012-05-17T13:12:32.507 回答