如何获取 asp.net 匿名身份验证令牌以支持配置文件?
所以我有一个 asp.net Web 应用程序(不是网站),我试图支持匿名用户的配置文件。我有一个表单,我希望匿名用户只能输入一次姓名和电子邮件,并在下次加载时自动访问该信息。
在我的 Web.config 中,我有匿名 ID 设置,如下所示:
<anonymousIdentification enabled="true" cookieless="AutoDetect" />
我的配置文件部分设置如下:
<profile defaultProvider="SqlProvider" enabled="true" inherits="QA_Web_Tools.UserProfile">
<providers>
<clear />
<add connectionStringName="QAToolsConnectionString" name="SqlProvider"
type="System.Web.Profile.SqlProfileProvider" />
</providers>
</profile>
最后,由于我的应用程序是 Web 应用程序而不是网站,我通过此自定义对象使用配置文件:
public class UserProfile : ProfileBase
{
public static UserProfile GetUserProfile(string username)
{
return Create(username) as UserProfile;
}
public static UserProfile GetUserProfile()
{
return Create(Membership.GetUser().UserName) as UserProfile;
}
[SettingsAllowAnonymous(true)]
public string FullName
{
get { return base["FullName"] as string; }
set { base["FullName"] = value; }
}
[SettingsAllowAnonymous(true)]
public string BuildEmail
{
get { return base["BuildEmail"] as string; }
set { base["BuildEvmail"] = value; }
}
}
此代码基于
问题是该代码不支持匿名用户,或者如果支持,我不知道如何支持。我无法使用不带参数的 GetUserProfile()
方法,因为如果用户是匿名的,则 Membership.GetUser()
为 null。我可以将匿名 ID 令牌传递到第一个 GetUserProfile(string username)
方法,但我找不到任何方法来获取当前用户的匿名 ID 令牌。
有谁知道如何获取这些信息?谷歌似乎没有返回有用的结果。
谢谢,
So I have an asp.net Web Application (Not Web Site) that I am trying to support profiles for anonymous users. I have a form and I want anonymous users to be able to enter their name and email only once, and have that information automatically accessible on the next load for them.
In my Web.config I have anonymous ID setup like so:
<anonymousIdentification enabled="true" cookieless="AutoDetect" />
I have my profile section setup like this:
<profile defaultProvider="SqlProvider" enabled="true" inherits="QA_Web_Tools.UserProfile">
<providers>
<clear />
<add connectionStringName="QAToolsConnectionString" name="SqlProvider"
type="System.Web.Profile.SqlProfileProvider" />
</providers>
</profile>
Finally, due to my app being a Web App and not a Web Site, I am using the profiles via this custom object:
public class UserProfile : ProfileBase
{
public static UserProfile GetUserProfile(string username)
{
return Create(username) as UserProfile;
}
public static UserProfile GetUserProfile()
{
return Create(Membership.GetUser().UserName) as UserProfile;
}
[SettingsAllowAnonymous(true)]
public string FullName
{
get { return base["FullName"] as string; }
set { base["FullName"] = value; }
}
[SettingsAllowAnonymous(true)]
public string BuildEmail
{
get { return base["BuildEmail"] as string; }
set { base["BuildEvmail"] = value; }
}
}
This code is based off of this reference.
The issue is that that code does not support anonymous users, or if it does I don't know how. I can't use the GetUserProfile()
method with no parameters because if the user is anonymous, Membership.GetUser()
is null. I could pass in the anonymous ID token into the first GetUserProfile(string username)
method but I cant' find any way to get the anonymous ID token for the current user.
Does anyone know how to get this information? Google doesn't seem to be returning useful results.
Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
成功!
我改变了:
现在
它可以工作了!
Success!
I changed:
to
and now it works!