我想在我的asp.net mvc 3应用程序中有自定义配置文件提供程序。问题是,我不想使用由ASP.NET Membership/Role/Profile提供程序生成的默认数据库,这主要是因为身份验证已经使用WebService完成,并且数据库已经存在。asp.net mvc自定义配置文件提供程序
我想要用户配置文件属性来填充它们并在站点的不同区域内使用。
我接过来一看这个例子(How to assign Profile values?),但我收到此错误:
An attempt to attach an auto-named database for file C:\Projects\FWManager\App_Data\aspnetdb.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
这里是web.config中
<profile inherits="FWMembership.Membership.FWProfileProvider" defaultProvider="AspNetSqlProfileProvider" automaticSaveEnabled="false" enabled="true">
<providers>
<clear/>
<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/" />
</providers>
</profile>
这是我的自定义类
public class FWProfileProvider : ProfileBase
{
[SettingsAllowAnonymous(false)]
public string FirstName
{
get { return base["FirstName"] as string; }
set { base["FirstName"] = value; }
}
[SettingsAllowAnonymous(false)]
public string LastName
{
get { return base["LastName"] as string; }
set { base["LastName"] = value; }
}
[SettingsAllowAnonymous(false)]
public int? UserID
{
get { return base["UserID"] as int?; }
set { base["UserID"] = value; }
}
[SettingsAllowAnonymous(false)]
public string UserCompany
{
get { return base["UserCompany"] as string; }
set { base["UserCompany"] = value; }
}
[SettingsAllowAnonymous(false)]
public string Email
{
get { return base["Email"] as string; }
set { base["Email"] = value; }
}
public StringCollection Entitlements
{
get { return base["Entitlements"] as StringCollection; }
set { base["Entitlements"] = value; }
}
public string username;
public FWProfileProvider()
{
}
public FWProfileProvider(string username)
{
this.username = username;
}
static public FWProfileProvider CurrentUser
{
get
{
return (FWProfileProvider)
(ProfileBase.Create("Joe"));
}
}
}
关键是要避免使用asp.net默认成员表。 任何想法?
编辑: 忘了补充 - 这个web应用程序,但概况提供者被放置在同一soulution内的类库项目: 解决方案 | - > FWProfile(类库项目) | - > UI(ASP .net mvc 3 web应用程序)
所以我的假设是,我必须实现自定义成员资格提供程序并将其调整到当前应用程序(使用WebService进行身份验证,而不是直接调用数据库)。我对么? – 303 2011-05-26 18:13:27
如果你不想使用标准的用户管理,你必须编写自己的提供者,这是正确的。 – slfan 2011-05-27 05:13:31
现在它变得更有趣了。获取不同的错误 - 解析器错误消息:提供者必须实现类“System.Web.Profile.ProfileProvider”。 – 303 2011-05-27 10:00:42