zoukankan      html  css  js  c++  java
  • 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>

  • 相关阅读:
    jvm基本结构和解析
    多态的意思
    java中对象的简单解读
    double类型和int类型的区别
    python 解析xml文件
    win10不能映射Ubuntu共享文件
    Qt程序打包
    Ubuntu boot分区文件误删,系统无法启动,怎么解
    ubuntu Boot空间不够问题“The volume boot has only 5.1MB disk space remaining”
    Ubuntu 分辨率更改 xrandr Failed to get size of gamma for output default
  • 原文地址:https://www.cnblogs.com/rr163/p/3997673.html
Copyright © 2011-2022 走看看