asp.net Context.User.Identity.Name说明

今天做了一个身份验证页面,基本实现功能,却不能显示当前用户姓名,自己MSDN半天一无所获,问题就在Context.User.Identity.Name;Context是HttpContext类,User属性Gets or sets security information for the current HTTP request,再查identity是IIdentity类型的接口;Name是它的Public Properties,可以Gets the name of the current user。依旧木有办法。网上的大虾们说是验证方式的问题,就知道Form方式,加到Web.cofig里,直接搞定!!!!

////////////////////////////粘网络资源,共享快乐

(1)在ASP.NET中有三种身份验证方式。当使用其中的一种来验证当前用户并通过时,必然要在服务器及客户端之间保存一种验证票据来保存验证信息。.NET提供类似于IIdentity的接口来完成该功能。请楼主注意,context.user是IPrincipal类型接口,而identity是IIdentity类型的接口。有四种类FormsIdentity GenericIdentity PassportIdentity WindowsIdentity实现了IIdentity接口。这几种类对应于.NET的几种验证模式。以上也差不多是废话,只是说了一下。 不过,请楼主看一下以上说的, 再对MSDN里查找一下ASP.NET的Forms验证的文章。看一下在forms验证时对FormsIdentity类的使用,有些信息保存到FormsIdentity类的实例里,在使用的时候就可以context.user.identity.name提取出来。

(2)Context.User.Identity.Name总是为空,望高手指教为什么?
______________________________________________________________________________________________
答1:
are you using forms-based authentication or windows integrated authentication?
______________________________________________________________________________________________
答2:
你把asp.net改为windows内置验证,Context.User.Identity.Name就有值了
______________________________________________________________________________________________
答3:
up

附上:Web.config//只解决本问题,其他问题再说

<system.web>
<authentication mode = "Forms">

</system.web>

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。