Membership.GetUser()的应用程序启动时,返回null [英] Membership.GetUser() is returning null when app starts

查看:102
本文介绍了Membership.GetUser()的应用程序启动时,返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实现了我自己的 AccountProfile 类是ASP.net MVC和它工作,但现在我遇到了一个奇怪的问题。首先,我在查看/共享/ _LoginPartial.cshtml调用AccountProfile.MyProperty。 AccountProfile.MyProperty使得以Membership.GetUser()。用户名调用工作。现在,当我注册的一个账户,我登录后,AccountProfile.MyProperty工作并呈现信息到HTML页面。

I've implemented my own AccountProfile class is ASP.net MVC and it works but now I'm running into a strange problem. First off, I'm calling AccountProfile.MyProperty in the Views/Shared/_LoginPartial.cshtml. AccountProfile.MyProperty makes a call to Membership.GetUser().UserName to work. Now, when I "signup" for an account, after I'm logged in, AccountProfile.MyProperty works and renders info into the html page.

然而,当我停止运行,改变一些code,并再次启动,Membership.GetUser()返回null,即使我仍然登录根据会员资格。

However when I stop running, change some code, and launch again, Membership.GetUser() returns null, even though I'm still logged in according to membership.

该页面无法加载,如果我浏览到/帐号/登录页面后,Membership.GetUser()的作品。它的工作原理之后,我就可以导航到该索引页未在开始工作,它的工作原理。

After the page fails to load, if I navigate to the /Account/Login page, Membership.GetUser() works. After it works, I can then navigate to the index page that didn't work at start, and it works.

我的问题是为什么Membership.GetUser()返回NULL,当​​我第一次加载页面呢?

My question is why does Membership.GetUser() return null when my page first loads up?

感谢。

推荐答案

好吧,我发现周围的车Membership.GetUser()函数的工作。

Alright, I found a work around the buggy Membership.GetUser() function.

HttpContext.Current.User.Identity.Name

这件code的被登录的用户名,它实际上似乎工作。如果我有任何问题,我会在这里报到。

This piece of code gets the logged in users name, and it actually appears to work. If I have any problems with it I'll report back here.

这篇关于Membership.GetUser()的应用程序启动时,返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆