How does Request.IsAuthenticated work?
How does Request.IsAuthenticated work?
MSDN Code Sample Description: The following code example uses the IsAuthenticated property to determine whether the current request has been authenticated. If it has not been authenticated, the request is redirected to another page where users can enter their credentials into the Web application. This is a common technique used in the default page for an application.
This is great but no detail or anything...
What exactly is it checking for? How do I set it to true?
Go the extra mile: Where would I find more detailed documentation about this?
Thanks to Google, I found a cached version of the post @keyboardP refers to in his answer. I'm posting that answer/post here as a reference for others since the original link is broken (2012-12-06).
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 as Context.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
so Request.IsAuthenticated
will be false
. When an authentication module handles the Application_AuthenticateRequest
event and successfuly authenticates the user it replaces the GenericIdentity
in Context.User.Identity
with a new IIdentity
object that will return true
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 returns True
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 with IsAuthenticated
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.
How does Request.IsAuthenticated work?的更多相关文章
- 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 ...
- Request.IsAuthenticated
Original question that the answer below refers to: I have a forms based application that is giving m ...
- 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所在计算机是否已添加到域中:右击计算机->属性,在计算机名称,域,工作组设置中可看到计算机所在的域,若没有,可点击更改设置,再点击更改,选择要绑定的域即可(需要用域账户登录). ...
随机推荐
- sql server统计总成绩和排名
这里的图片可以拖拽到一个新页面查看原图!!!! 这里有两个表,需要查询总成绩和排名 Sql语句: select ST.name,SE.Chinese,SE.Math,SE.English, ( SE. ...
- cell上的按钮点击和左滑冲突
cell上的某个按钮的点击事件,当cell左滑的时候,只要活动的区域也在按钮上,那么按钮的点击事件也会调用. fix: 给按钮添加一个手势(TapGesture)那么当点击的时候就会响应点击手势的方法 ...
- 流程控制 while for
循环执行 计算机最擅长的功能之一就是按照规定的条件,重复执行某些操作,这是程序设计中最能发挥计算机特长的程序结构. 1.while语句 while(表达式){ 各种语句.... } 当表达式的值为tr ...
- C#-NPOI操作EXCEL
1.获取NUGET NPOI包. 2.引用命名空间 using NPOI.SS.UserModel;using NPOI.XSSF.UserModel;using NPOI.HSSF.UserMode ...
- RestFramework之解析器
一.什么是解析器? 对请求的数据进行解析 - 请求体进行解析. 解析器在你不拿请求体数据时 不会调用. 安装与使用: https://www.django-rest-framework.org/ 官方 ...
- 解决npm安装时出现run `npm audit fix` to fix them, or `npm audit` for details 的问题
npm audit fix npm audit fix --force npm audit 按照顺序一一运行亲测完全可用如果还是不行的话,可以把node_modules和package-lock.js ...
- 使用aop注解实现表单防重复提交功能
原文:https://www.cnblogs.com/manliu/articles/5983888.html 1.这里采用的方法是:使用get请求进入表单页面时,后台会生成一个tokrn_flag分 ...
- 部署Nginx网站服务实现访问状态统计以及访问控制功能
原文:https://blog.51cto.com/11134648/2130987 Nginx专为性能优化而开发,最知名的优点是它的稳定性和低系统资源消耗,以及对HTTP并发连接的高处理能力,单个物 ...
- PAT基础级-钻石段位样卷2-7-7 危险品装箱 (25 分)
集装箱运输货物时,我们必须特别小心,不能把不相容的货物装在一只箱子里.比如氧化剂绝对不能跟易燃液体同箱,否则很容易造成爆炸. 本题给定一张不相容物品的清单,需要你检查每一张集装箱货品清单,判断它们是否 ...
- 2019-ACM-ICPC-徐州站网络赛- I. query-二维偏序+树状数组
2019-ACM-ICPC-徐州站网络赛- I. query-二维偏序+树状数组 [Problem Description] 给你一个\([1,n]\)的排列,查询\([l,r]\)区间内有多少对 ...