首页 > Web开发 > 详细

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

时间:2014-09-28 10:05:12      阅读:275      评论:0      收藏:0      [点我收藏+]

今天做了一个身份验证页面,基本实现功能,却不能显示当前用户姓名,自己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>

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

原文:http://www.cnblogs.com/rr163/p/3997673.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!