ASP.Net登录和用户认证 [英] ASP.Net Login & User Authentication
本文介绍了ASP.Net登录和用户认证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用asp.net成员资格.我的login.aspx页面转到loginredirect.aspx
用户登录后的页面.
由于某种原因,"Membership.GetUser.ProviderUserKey.ToString"给了我这个
错误:
System.NullReferenceException:对象引用未设置为
的实例
对象.
有什么原因吗?我应该可以正常登录.
还有其他方法可以获取当前用户的UserId吗?
提前thanx..
Using asp.net membership. My login.aspx page goes to the loginredirect.aspx
page after the user logs in.
For some reason "Membership.GetUser.ProviderUserKey.ToString" gives me this
error:
System.NullReferenceException: Object reference not set to an instance of an
object.
Any reason why? I should be logged in fine.
Is there another way in which I should get the current users UserId?
thanx in advance..
推荐答案
您需要执行Membership.GetUser并查看其是否为null.如果它为null而不是未登录,那么您的示例代码字符串提供了两个实例,我可以看到在哪里可以出现null引用. 1)如果getuser返回null,并且2)如果ProviderUserKey为null.
You need to do Membership.GetUser and see if it''s null. If it''s null than you''re not logged in. Your example code string provides two instances I can see where a null ref can occur. 1) if getuser returns null and 2) if ProviderUserKey is null.
始终使用调试器.沃森小学.
一种可能的原因是:
Membership.GetUser == null
.
如果不是,则另一个可能的原因是:
Membership.GetUser.ProviderUserKey == null
.
就是这样,只有这两种情况.但是,如果您使用了调试器,则无需在此CodeProject页上写一行.
最好的问候,
—SA
Always use the Debugger. Elementary, Watson.
One possible reason is:
Membership.GetUser == null
.
If not, another possible reason is:
Membership.GetUser.ProviderUserKey == null
.
And that''s it, nothing except these two cases. But if you used the Debugger, you would not need to write a single line on this CodeProject page.
Best regards,
—SA
这篇关于ASP.Net登录和用户认证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文