用户通过身份验证后(Windows)会触发事件吗?我在Application_Start()执行,但它返回false User.Identity.IsAuthenticated
。用户通过身份验证后触发事件 - Windows身份验证
我想要的是创建角色并手动添加到用户。
用户通过身份验证后(Windows)会触发事件吗?我在Application_Start()执行,但它返回false User.Identity.IsAuthenticated
。用户通过身份验证后触发事件 - Windows身份验证
我想要的是创建角色并手动添加到用户。
Application_Start()在请求ASP.NET应用程序中的第一个资源(如页面)时被调用。另外,在应用程序的生命周期中它只被调用一次。据说,在那个时候,你将无法授权所有的用户。客户端计算机上的当前Windows用户信息由Web浏览器通过密码交换提供,涉及与Web服务器 [Wiki]进行哈希处理。只有这样你才能授权用户。因此,User.Identity.IsAuthenticated应该在页面加载时工作(请参阅下面的代码)。您可以提取你需要的常用方法的逻辑,并调用它的第一次加载页面
protected void Page_Load(object sender, EventArgs e)
{
if (User.Identity.IsAuthenticated)
{
Page.Title = "Home page for " + User.Identity.Name;
// add your logic here
}
else
{
// you get here if auth failed.
Page.Title = "Home page for guest user.";
}
}
更多信息的更新后:
我会使用的Application_Start()检查和如果它们不存在,则添加角色。
if (! Roles.RoleExists("Auditors"))
Roles.CreateRole("Auditors");
我用这个:
protected void Application_AuthenticateRequest(Object sender, EventArgs e)
{
if (HttpContext.Current.User != null)
{
if (HttpContext.Current.User.Identity.IsAuthenticated)
{
if (HttpContext.Current.User.Identity is WindowsIdentity)
{
if (string.IsNullOrEmpty(Usuario.Nome))
{
确保,在你的项目性质(ALT项目+输入)点击WEB检查NTLM AUTHENTICATION。
这对我有效。现在HttpContext.Current.User.Identity
不再为空
微软不再在应用程序中推荐NTLM – 2014-10-30 16:10:31
这是它工作的唯一方式,所有其他方式User.Identity.IsAuthenticated是null当从Visual Studio – 2014-10-30 16:22:36
运行应用程序你可以试试这个吗? http://stackoverflow.com/questions/1663535/httpcontext-current-user-is-null-even-though-windows-authentication-is-on – 2014-10-30 16:26:09
您好,我想是这样的:保护无效Application_AuthenticateRequest(对象发件人,EventArgs的){ 如果 (HttpContext.Current.User!= NULL){ 如果 (HttpContext.Current。 (HttpContext.Current.User.Identity是WindowsIdentity) var amduser = new UsuarioDB();如果(HttpContext.Current.User.Identity是WindowsIdentity) var amduser = new UsuarioDB();如果(HttpContext.Current.User.Identity是WindowsIdentity) amduser.DefinirPropriedadesUsuario(); } } } }但Current.User.Identity始终为空 – 2014-10-30 12:26:28
@ user1200656,可以试试吗? http://stackoverflow.com/questions/1663535/httpcontext-current-user-is-null-even-though-windows-authentication-is-on – 2014-10-30 15:44:12