FormsAuthentication Membership.GetUser()空 [英] FormsAuthentication Membership.GetUser() Null

查看:128
本文介绍了FormsAuthentication Membership.GetUser()空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用窗体身份验证,并具备基本的登录页面,默认的页面。

I am using Forms Authentication and have the basic logon page and default page.

当我在登录页上,并调用点登录这工作好了。然而,当我还在登录页面上的 Membership.GetUser()返回null。当我重定向到我的默认页面,在 Membership.GetUser()返回我的用户信息。

When I am on the logon page, and call the SignOn this works just great. However, when I am still on the Logon page the Membership.GetUser() returns null. When I redirect to my default page, the Membership.GetUser() returns my user information.

有什么这样我得到得到这个方法返回我的用户,同时仍然在登录页上。我已阅读遍谷歌,其他有类似问题的地方,一旦你重定向才会工作。

Is there any way I get get this method to return my user while still on the logon page. I have read all over google that other have similar issues where it will only work once you redirect.

让我知道如果你需要进一步的信息。

Let me know if you need further information.

下面是我使用验证信息被设定什么样的一个简单的代码片段:

Here is a simple code snippet of what I am using to verify that the information is being set:

bool authenticated = User.Identity.IsAuthenticated;
            string username = User.Identity.Name;

            MembershipUser user = Membership.GetUser();



我把这段代码同时登录页面,并在代码中的默认页面上的落后,只有默认页面有价值观和显示身份验证过程执行后,将会对其进行认证。

I put this code on both the logon page and the default page in the code behind and only the default page has values and shows that it is authenticated after the authentication process executes.

推荐答案

这可能是因为你允许匿名用户的登录页面。因此,浏览器不打扰发送给这个页面比是必要的任何信息。

This might be because you allow anonymous users on your login page. Therefore the browser doesn't bother sending any more information to this page than is necessary.

这篇关于FormsAuthentication Membership.GetUser()空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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