1
可能性の重複:
.NET Application_BeginRequest - How to get User reference?asp.netログイン制御やGlobal.asaxの中にログインしたユーザー
私はASPのログイン制御に問題があります。 web.configファイルでForms認証モードを設定しました.Global.asax - > Application_BeginRequestメソッドでログに記録されたユーザーデータを取得します。
.aspxのコードスニペット:
<asp:Login OnAuthenticate="Login1_Authenticate" ID="LoginUser" runat="server">
[...]
</asp:Login>
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{
if (Membership.ValidateUser(LoginUser.UserName, LoginUser.Password))
{
FormsAuthentication.SetAuthCookie(LoginUser.UserName, LoginUser.RememberMeSet);
}
}
Global.asaxのコードスニペット
protected void Application_BeginRequest(object sender, EventArgs e)
{
var usr = HttpContext.Current.User;
}
HttpContext.Current.User
プロパティがnullである - なぜ?