Request.IsAuthenticated
Original question that the answer below refers to:
I have a forms based application that is giving me fits. I noticed that, in a location where the IsAuthenticated property had been True, it was now false and the was not working as expected. I am wondering if I have a setting that is invalid??
Can anyone tell me what sets the IsAuthenticated property to True--what constitues logging in.
Answer by Daniel Kent:
Request.IsAuthenticated is not just for forms authentciation - it is valid no matter what type of authentication is being used (Windows, Passport, Forms or our own custom scheme)
HttpRequest.IsAuthenticated will be true when the user making the request has been authenticated. Essentially, this property provides the same information asContext.User.Identity.IsAuthenticated.
At the start of a request, Context.User.Idenity contains a GenericIdentity with a null username. The IsAuthenticated property for this object will return false soRequest.IsAuthenticated will be false. When an authentication module handles theApplication_AuthenticateRequest event and successfuly authenticates the user it replaces theGenericIdentity in Context.User.Identity with a new IIdentity object that will returntrue from its IsAuthenticated property. Request.IsAuthenticated will then return true.
In the case of Forms authentication, the forms authentication module uses the encrypted authentication ticket contained in the authentication cookie to authenticate the user. Once it has done this, it replaces the GenericIdentity in Context.User.Identity with a FormsIdentity object that returnsTrue from its IsAuthenticated property.
So, setting IsAuthenticated to true is actually different to logging in. As Jeff says, logging in to forms authentication happens when the authentication ticket is generated and sent to the client as a cookie. (RedirectFromLoginPage or SetAuthCookie) What we are talking about withIsAuthenticated is authentication that happens with each page request. Logging in happens when a user enters their credentials and is issued a ticket, authentication happens with each request.
使用Request.IsAuthenticated时,一般要设置认证模式为:Passport或Forms,否则认证会得不到期望的结果。
Request.IsAuthenticated的更多相关文章
- MVC Request.IsAuthenticated一直false Request.Cookie获取不到cookie
项目中,在做登录验证时,用到了cookie,同一账户登陆,可以.切换其他账号时,就在也登录不上了,用原来的也不行.检查Request.IsAuthenticated一直false,而且Request. ...
- 今天发现猎豹浏览器的一个大坑 Request.IsAuthenticated 一直为 false;另外附加原因以及临时的解决方法
今天掉到了一个大坑里面,爬了1个多小时才发现不是代码的问题,居然是浏览器的问题… 下面是问题的发生过程 单点登陆 有2个站点 http://a.abc.com http://b.abc.com ...
- How does Request.IsAuthenticated work?
How does Request.IsAuthenticated work? MSDN Code Sample Description: The following code example uses ...
- Asp.net MVC Form认证,IIS改成集成模式后,FormsAuthentication.SetAuthCookie无效,Request.IsAuthenticated值,始终为false,页面提示HTTP 错误 401.0 - Unauthorized,您无权查看此目录或页面
最近公司领导要求,IIS网站要由经典模式改为集成模式,以提高性能.改完之后,登录成功跳转到主页之后,页面提示“”HTTP 错误 401.0 - Unauthorized“,“您无权查看此目录或页面”, ...
- 搞了我一下午竟然是web.config少写了一个点
Safari手机版居然有个这么愚蠢的bug,浪费了我整个下午,使尽浑身解数,国内国外网站搜索解决方案,每一行代码读了又想想了又读如此不知道多少遍,想破脑袋也想不通到底哪里出了问题,结果竟然是web.c ...
- .NET Web的身份认证
百度一下”asp.net身份认证“,你会得到很多相关的资料,这些资料通常上来就会介绍诸如”Form认证“”Windows认证“等内容,而没有给出一个完整的流程.初学者对此往往一头雾水,我也曾经被坑过很 ...
- 分享一个html+js+ashx+easyui+ado.net权限管理系统
EasyUI.权限管理 这是个都快被搞烂了的组合,但是easyui的确好用,权限管理在项目中的确实用.一直以来博客园里也不少朋友分享过,但是感觉好的要不没源码,要不就是过度设计写的太复杂看不懂,也懒得 ...
- [转]Asp.Net 用户验证(自定义IPrincipal和IIdentity)
本文转自:http://www.cnblogs.com/amylis_chen/archive/2012/08/02/2620129.html Default.aspx 页面预览 默认情况下SignI ...
- IIS配置域用户自动登录
1.首先确定IIS所在计算机是否已添加到域中:右击计算机->属性,在计算机名称,域,工作组设置中可看到计算机所在的域,若没有,可点击更改设置,再点击更改,选择要绑定的域即可(需要用域账户登录). ...
随机推荐
- FileZilla Server配置
1.在服务器上安装并配置服务端: 安装过程这里不再赘述,一直下一步,在跳出弹窗时勾选“Always connect to this server”,然后点击“Connect”即可(密码可自行设置) 之 ...
- 从hello world 说程序运行机制
转自:http://www.cnblogs.com/yanlingyin/archive/2012/03/05/2379199.html 开篇 学习任何一门编程语言,都会从hello world 开始 ...
- 进程间通信IPC之--无名管道(pipe)和有名管道(fifo)(转)
进程间通信IPC之--无名管道(pipe)和有名管道(fifo) 2012-01-17 22:41:20 分类: C/C++ 每个进程各自有不同的用户地址空间,任何一个进 程的全局变量在另一个进程中 ...
- bzoj 1070 [SCOI2007]修车——网络流(拆边)
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1070 后面还有几辆车在这个人这儿修,自己这辆车的时间对总时间的贡献就要多乘上几倍. 所以可以 ...
- SharePoint2013工作流workflow manager配置
SharePoint2013版本的工作流较sharepoint 2010变化较大,将工作流部分从sharepoint中分离出来为单独的服务,通过与sharepoint关联使用. SharePoint2 ...
- 关于RedHat Enterprise Linux 6.4使用Centos 6 的yum源
思路:卸载redhat自带yum,然后下载centos的yum,安装后修改配置文件 1.首先到http://mirrors.163.com/centos下载软件包 x86 地址:http://mirr ...
- ubuntu :安装skype聊天工具
如题,今天就想搞个软件在ubuntu能聊天,查一下skype,好像网上有人说不是每个安装包都用的了,skype-ubuntu-precise_4.2.0.13-1_i386.deb可以, 我在微盘下载 ...
- Ninject Lazy Load
namespace LayzyLoadTest { [TestClass] public class UnitTest1 { private IKernel InitKernel() { Ninjec ...
- EFCodeFirst使用Nuget更新数据库
在MVC开发中,习惯于使用EF作为数据库操作,相对于传统的Ado.Net的数据库操作方式,EF大大的节省了我们手写SQL语句的时间,即便是传统的使用代码生成的方式.EF操作数据库目前分为两种大的方式. ...
- oracke创建db link
-- Create database link create public database link test_link connect to 用户名 identified by 密码 using ...