且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在ASP.NET MVC中实现配置文件提供

更新时间:2022-12-05 21:56:00

下面是你需要做的:

1)在Web.config中的部分,增加了继承属性,除了您的其他属性设置:

1) In Web.config's section, add "inherits" attribute in addition to your other attribute settings:

<profile inherits="MySite.Models.ProfileCommon" defaultProvider="....

2)删除整个&LT;性状&gt;从Web.config文件部分,既然您已经定义了它们在自定义ProfileCommon类,并指示从您的自定义类继承在previous步

2) Remove entire <properties> section from Web.config, since you have already defined them in your custom ProfileCommon class and also instructed to inherit from your custom class in previous step

3)更改ProfileCommon.GetProfile()方法的code到

3) Change the code of your ProfileCommon.GetProfile() method to

public virtual ProfileCommon GetProfile(string username)        
{            
     return Create(username) as ProfileCommon;      
}

希望这有助于。