Reputation: 29
I am trying to get my website to work the way Twitter.com works. If you are not logged in, www.twitter.com, first page that opens up is the homepage which allows the guest to log in/register. However, if this is not the first time you have visted the website, you remain logged in, and the next time you go to www.twitter.com, the first page that loads is the timeline.
From the homepage page load I tried the following code but I'm pretty sure it's not right
protected void Page_Load(object sender, EventArgs e)
{
if (Login1.LoggedIn == true)
{
Response.Redirect("abc.aspx");
}
}
There's a red error line underneath LoggedIn saying "Expression to evaluate"
How could I correct this, so if a user is already logged in, the first page that loads is abc.aspx
Upvotes: 0
Views: 3299
Reputation: 4634
Try checking the HttpContext instead.
protected void Page_Load(object sender, EventArgs e)
{
if (User.Identity.IsAuthenticated)
{
Response.Redirect("abc.aspx");
}
}
And you could add this with the code above to make sure they go to abc.aspx when the actual login happens.
protected void Login1_LoggedIn(object sender, EventArgs e)
{
Response.Redirect("abc.aspx");
}
More info about the login control http://forums.asp.net/t/1403132.aspx/1
Upvotes: 3
Reputation: 18061
If you are using Forms Authentication
just use defaultUrl="abc.aspx"
.
web.config example
<authentication mode="Forms">
<forms loginUrl="Login.aspx" defaultUrl="abc.aspx" />
</authentication>
See forms Element for authentication (ASP.NET Settings Schema) for details.
Upvotes: 2