ASP.NET 自定义配置文件错误

发布于 2024-10-15 00:05:34 字数 2143 浏览 1 评论 0原文

我对 ASP.NET 配置文件实现有疑问。这是我的个人资料代码:

public class UserProfile: ProfileBase
{
    public static void Get()
    {
        return (UserProfile)Create(Membership.GetUser().UserName);   
    }
    public static void Get(string username)
    {
        return (UserProfile)Create(username);
    }

    //this property works
    [SettingsAllowAnonymous(false)]
    public string FirstName
    {
        get{ return base.GetProperty("FirstName") as String; }
        set{ base.SetPropertyValue("FirstName", value); }
    }

    //this property works
    [SettingsAllowAnonymous(false)]
    public string LastName
    {
        get{ return base.GetProperty("LastName") as String; }
        set{ base.SetPropertyValue("LastName", value); }
    }

    //this property throws "The settings property 'Email' was not found." error.
    [SettingsAllowAnonymous(false)]
    public string EmailAddress
    {
        get{ return base.GetProperty("Email") as String; }
        set{ base.SetPropertyValue("Email", value); }
    }

    //this property throws "The settings property 'Telephone' was not found." error.
    [SettingsAllowAnonymous(false)]
    public string TelephoneNumber
    {
        get{ return base.GetProperty("Telephone") as String; }
        set{ base.SetPropertyValue("Telephone", value); }
    }
}

我的网络配置如下所示:

<profile inherits="UserProfile" defaultProvider="SqlProfileProvider">
    <providers>
        <add 
            name="SqlProfileProvider" 
            type="System.Web.Profile.SqlProfileProvider"
            connectionStringName="Profile" 
            applicationName="Management" />
    </providers>
</profile>

由于某种原因,当代码执行并且我检索或更新当前用户的个人资料时,它会崩溃。然而,更奇怪的是 FirstName 和 LastName 属性工作正常。仅当访问/更新 EmailAddress 和 TelephoneNumber 属性时才会发生错误。

如果我在 web.config 配置文件部分中为 FirstName、LastName、EmailAddress 和 TelephoneNumber 属性添加 部分,则会显示不同类型的错误 - “属性已定义”或其他内容沿着这条线......

关于如何解决这个问题有什么想法吗?您还需要知道配置文件系统的后端是 SQL Azure,而前端是 Azure WCF 服务。

谢谢,

<bleepzter/>

I have an issue with an ASP.NET profile implementation. This is my profile code:

public class UserProfile: ProfileBase
{
    public static void Get()
    {
        return (UserProfile)Create(Membership.GetUser().UserName);   
    }
    public static void Get(string username)
    {
        return (UserProfile)Create(username);
    }

    //this property works
    [SettingsAllowAnonymous(false)]
    public string FirstName
    {
        get{ return base.GetProperty("FirstName") as String; }
        set{ base.SetPropertyValue("FirstName", value); }
    }

    //this property works
    [SettingsAllowAnonymous(false)]
    public string LastName
    {
        get{ return base.GetProperty("LastName") as String; }
        set{ base.SetPropertyValue("LastName", value); }
    }

    //this property throws "The settings property 'Email' was not found." error.
    [SettingsAllowAnonymous(false)]
    public string EmailAddress
    {
        get{ return base.GetProperty("Email") as String; }
        set{ base.SetPropertyValue("Email", value); }
    }

    //this property throws "The settings property 'Telephone' was not found." error.
    [SettingsAllowAnonymous(false)]
    public string TelephoneNumber
    {
        get{ return base.GetProperty("Telephone") as String; }
        set{ base.SetPropertyValue("Telephone", value); }
    }
}

My web config looks like this:

<profile inherits="UserProfile" defaultProvider="SqlProfileProvider">
    <providers>
        <add 
            name="SqlProfileProvider" 
            type="System.Web.Profile.SqlProfileProvider"
            connectionStringName="Profile" 
            applicationName="Management" />
    </providers>
</profile>

For some reason when the code executes and I retrieve or update a profile for the current user it blows up. However, what is more curious is that the FirstName and LastName properties work fine. The errors only occur when accessing/updating the the EmailAddress and TelephoneNumber properties.

If I add the <properties> section in the web.config profile section for the FirstName, LastName, EmailAddress, and TelephoneNumber properties a different type of error shows up - "Property is already defined" or something along the lines...

Any ideas on how to fix this? Also you need to know that the back-end for the profile system is SQL Azure, while the front-end is an Azure WCF service.

Thanks,

<bleepzter/>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北风几吹夏 2024-10-22 00:05:34

您确定将字段名称与属性名称相匹配吗?电子邮件 != 电子邮件地址 &&电话 != 电话号码

Are you sure you are matching your field names with the property names? Email != EmailAddress && Telephone != TelephoneNumber

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文