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>

  • 相关阅读:
    服务器上往Mongo导入json文件里的数据
    在Flask蓝图中使用动态URL前缀
    python 的 optparser库
    lowB 三人组
    Linux基础介绍
    html的q标签、blockquote标签
    单冒号伪元素和双冒号伪元素
    CSS中的伪元素选择器
    CSS中的选择器
    CSS中的关系选择器
  • 原文地址:https://www.cnblogs.com/rr163/p/3997673.html
Copyright © 2011-2022 走看看