使用FormsAuthentication.SetAuthCookie后,如何判断Request.IsAuthenticated状态?

2026-03-30 11:451阅读0评论SEO问题
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计202个文字,预计阅读时间需要1分钟。

使用FormsAuthentication.SetAuthCookie后,如何判断Request.IsAuthenticated状态?

我在使用VS2013 RC和MVC 5构建一个网站,尝试使用formsAuthentification,但网站上无法注册永久用户。我通过公司API验证用户名和密码后,成功返回,但想发布一个授权功能。

我正在使用VS2013 RC和MVC 5构建一个网站,我正在尝试使用formsAuthentification而不在我的网站上注册永久用户.

我发布到我公司的api来验证用户的名字和密码.当这成功返回时,我想发布一个授权cookie:

使用FormsAuthentication.SetAuthCookie后,如何判断Request.IsAuthenticated状态?

System.Web.Security.FormsAuthentication.SetAuthCookie(username, false);

在调用之后我看到.ASPXAUTH = … cookie.

但是,我无法进入模板的_LoginPartial.cshtml页面上的@if(User.Identity.IsAuthenticated)或者@if(Request.IsAuthenticated)块.

这种技术在MVC 4中对我有用,我试图将其弯曲以适应MVC 5的OWIN身份验证.

我需要在web.config中启用表单身份验证

<system.web> <authentication mode="Forms"> <forms loginUrl="~/Account/Login" timeout="2880" /> </authentication> ... </system.web>

本文共计202个文字,预计阅读时间需要1分钟。

使用FormsAuthentication.SetAuthCookie后,如何判断Request.IsAuthenticated状态?

我在使用VS2013 RC和MVC 5构建一个网站,尝试使用formsAuthentification,但网站上无法注册永久用户。我通过公司API验证用户名和密码后,成功返回,但想发布一个授权功能。

我正在使用VS2013 RC和MVC 5构建一个网站,我正在尝试使用formsAuthentification而不在我的网站上注册永久用户.

我发布到我公司的api来验证用户的名字和密码.当这成功返回时,我想发布一个授权cookie:

使用FormsAuthentication.SetAuthCookie后,如何判断Request.IsAuthenticated状态?

System.Web.Security.FormsAuthentication.SetAuthCookie(username, false);

在调用之后我看到.ASPXAUTH = … cookie.

但是,我无法进入模板的_LoginPartial.cshtml页面上的@if(User.Identity.IsAuthenticated)或者@if(Request.IsAuthenticated)块.

这种技术在MVC 4中对我有用,我试图将其弯曲以适应MVC 5的OWIN身份验证.

我需要在web.config中启用表单身份验证

<system.web> <authentication mode="Forms"> <forms loginUrl="~/Account/Login" timeout="2880" /> </authentication> ... </system.web>