为什么HttpContext.Current.User.Identity.Name返回空白 [英] Why does HttpContext.Current.User.Identity.Name return blank

查看:201
本文介绍了为什么HttpContext.Current.User.Identity.Name返回空白的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个网站。它是一个内部位点。这是一个.NET 4.0的网站。我想用抢浏览网站的人HttpContext.Current.User.Identity.Name的用户名。心不是有一个登录页面,因为它是内部的。我不知道我错过了什么。我需要在我的webconfig以下内容:

I created a site. It is an internal site. It is a .NET 4.0 site. I would like to grab the username using HttpContext.Current.User.Identity.Name of the person browsing the site. There isnt a login page since it is internal. I am not sure what I am missing. Do I need the following in my webconfig:

<authentication mode="Windows"></authentication>
<identity impersonate="true"/>
<authorization>
  <allow users="?"/>
</authorization>

和这样的:

  <system.webServer>
  <validation validateIntegratedModeConfiguration="false" />

推荐答案

它出现空白时,未经认证。你可以这样做也验证这一点:

It comes up blank when unauthenticated. You can verify this by also doing:

HttpContext.Current.User.Identity.IsAuthenticated

检查IIS身份验证级别,将其设置为启用Windows身份验证有太多?

Check your authentication level in IIS, is it set to enable windows authentication there too?

这篇关于为什么HttpContext.Current.User.Identity.Name返回空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆