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.

 

 

 

 

作者:Chuck Lu    GitHub    
posted @   ChuckLu  阅读(375)  评论(0编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
历史上的今天:
2018-09-12 sabaki and leelazero
2015-09-12 git ignore 的使用
2014-09-12 TeeChart缩放
点击右上角即可分享
微信分享提示