Request.IsAuthenticated总是返回false [英] Request.IsAuthenticated always returning false
问题描述
我的工作将登录功能到一个网站我建立,但是登录之后,Request.IsAuthenticated属性总是返回true。我已经搜索这个错误,并发现一遍又一遍同样的答案,但这些解决方案不是为我工作。
I am working on adding login functionality to a site I am building, but after login, the Request.IsAuthenticated property always returns true. I have searched this error and have found the same answers over and over, but those solutions are not working for me.
从的AccountController ::登录行动code:
Code from AccountController::Login action:
if (response.Status == KD.Core.Enumerations.LoginStatus.LoggedIn)
{
FormsAuthentication.SetAuthCookie(model.Username, model.RememberMe);
SessionMgr.GetInstance().SetSessionValue(SessionTypes.UserId, response.UserId);
//Have added logging here to ensure login is successful in prod.
return RedirectToAction("Index", "Home");
}
从那里我看到这个问题_layout视图文件code:
Code from _Layout view file where I am seeing the problem:
<ul class="profile-nav">
@if (Request.IsAuthenticated)
{
<li class="active"><a href="/Account/Logout" title="Logout">Logout</a></li>
}
else
{
<li class="active"><a href="/Account/Login" title="Login">Login</a></li>
}
</ul>
2. previous答案,我发现与在web.config中的窗体身份验证的配置,但我已经试过都和我仍然没能得到这个工作。如预期我的机器上的code函数(即...是登录后显示注销)。问题是,一旦我部署到我的督促Web服务器登录成功,但不显示注销链接,只有重新登录。我已验证的用户被登录为我增加了code写的,从登录操作(RedirectToAction调用前右)日志文件,所以我知道这是哪位SetAuthCookie,但一旦它击中布局$在随后重定向到我的主页(首页/索引)C $ c时,Request.IsAuthenticated不会永远返回true,所以我总是得到再次登录链接。 2东西我曾尝试是在web.config以下变动窗体身份验证:1)添加requireSSL =假2)加入该域CONTOSO=实际的域我督促Web服务器托管,但再次,没有这些有固定我的问题,我跑的想法。
The 2 previous answers I have found related to the forms authentication configuration in the web.config, but I have tried both and I am still not able to get this to work. The code functions as expected on my development machine (ie...Logout is displayed after logging in). The problem is that once I deploy to my prod web server the login is successful, but the Logout link is not displayed, only Login again. I have verified that the user is being logged in as I have added code to write to a log file from the Login action (right before the RedirectToAction call) so I know it is calling SetAuthCookie, but once it hits the layout code on the subsequent redirect to my home page (Home/Index), the Request.IsAuthenticated does not ever return true so I always get "Login" link again. The 2 things I have tried are the following changes to the web.config for forms auth: 1) adding the "requireSSL="false" 2) adding the domain where "contoso" = the actual domain my prod web server is hosting, but again, neither of these has fixed my issue and I'm running out of ideas.
<authentication mode="Forms">
<forms loginUrl="~/Account/Login" timeout="2880" requireSSL="false" domain="contoso.com" />
</authentication>
任何帮助是极大AP preciated。
Any help is greatly appreciated.
推荐答案
好吧....2个月撕扯我的头发后,我终于想通了这一点。在根应用程序级别的web.config中没有足够的runAllManagedModulesForAllRequests =真正的标志。一旦我添加了属性,该Request.IsAuthenticated检查返回真。
Well....after 2 months of ripping my hair out I finally figured this out. The web.config at the root application level did not have the "runAllManagedModulesForAllRequests=true" flag. Once I added that attribute, the Request.IsAuthenticated check returned true.
希望我的奋斗帮助别人,将来别人。
Hope my struggles help someone else in the future.
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"></modules>
</system.webServer>
这篇关于Request.IsAuthenticated总是返回false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!