[英]Communicating between login.aspx and default.aspx
I'm new to web development.我是 web 开发的新手。 I have a login.aspx page that has an Asp.Net
login control on it.我有一个 login.aspx 页面,上面有一个Asp.Net
登录控件。 When the users logs in and it successfully authenticates, the page automatically redirects to default.aspx.当用户登录并成功通过身份验证时,页面会自动重定向到 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
.但是,我实际上需要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 control-- 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?此外,我并不总是指望用户使用登录控件成功登录——如果我想在不发生登录事件的情况下重定向到default.aspx
,我该如何在传递登录信息的同时做到这一点?用过的?
You can call Membership.GetUser()
to get the currently-logged-in user.您可以调用Membership.GetUser()
来获取当前登录的用户。
You can do this sort of thing anywhere in your web app now that the user is authenticated and logged in.您可以在 web 应用程序中的任何位置执行此类操作,因为用户已通过身份验证并登录。
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.否则,您可以将值放入 session 变量中,然后在默认页面中访问它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.