Communicating between login.aspx and default.aspx
I'm new to web development. I have a login.aspx page that has an Asp.Net
login control on it. When the users logs in and it successfully authenticates, the page automatically redirects to default.aspx. I assume this is some kind of default behavior?
But, I actually need the login information from the login page in default.aspx.cs
. How do I get this information from that context?
In addition, I'm not always going to count on the user successfully logging in with the login c开发者_C百科ontrol-- If I want to redirect to default.aspx
without a login event occurring, how can I do that while also passing the login information being used?
You can call Membership.GetUser()
to get the currently-logged-in user.
You can do this sort of thing anywhere in your web app now that the user is authenticated and logged in.
MembershipUser mu = Membership.GetUser();
if (mu.PasswordQuestion == null || mu.PasswordQuestion.Length < 3)
{
Response.Redirect("~/Account/ChangePasswordQuestion.aspx");
}
If you need to get the username only, you can get it like..
HttpContext.Current.User.Identity.Name// it will return current logined username
Otherwise you can put the value in a session variable and then access it in the default page.
Use LoginView
control
精彩评论