lex*_*eme 10 c# sql-server asp.net-mvc mongodb
我选择将其mongodb
用作以域为中心的数据的存储.我正在寻找official mongodb providers
将它们集成到ASP.NET MVC
项目中以保留单个应用程序数据库.没有官方提供商,可用的提供商看起来不成熟/稳定.所以我决定使用简单的会员资格.
Entity Framework
如果可能的话,如何摆脱特定的代码AccountController
?
如何管理具有SimpleMembership UserProfile
和MongoDB
User
?的用户配置文件?
例
在单独的程序[project-name].domain
集中有两个类:
public class Event {
public DateTime ScheduledDate { get; set; }
public String Name { get; set; }
public Location Location { get; set; }
}
public class User {
public String Name { get; set; }
public List<Events> AssociatedEvents { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
如果我添加一个UserProfileId
,这将是一个解决方案User
吗?
public class User {
public Int32 UserProfileId { get; set; }
public String Name { get; set; }
public List<Events> AssociatedEvents { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
你必须使用appSetting中的connectionString.
您需要下载上面的fork,构建并更改现有的dll引用以使用新的dll.
然后...
使用你的配置:
<appSettings>
<add key="MONGOLAB_URL" value="mongodb://localhost/ASPNETDB"/>
</appSettings>
Run Code Online (Sandbox Code Playgroud)
...上面的值将被appharbor/mongolab取代(如果你有应用程序的其他部分工作,那么这是正确的)
<providers>
<clear />
<add name="MongoDBMembershipProvider" type="MongoDB.Web.Providers.MongoDBMembershipProvider"
applicationName="/" appSettingsConnectionStringKey="MONGOLAB_URL" collection="Users"
enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false"
maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" />
</providers>
Run Code Online (Sandbox Code Playgroud)
所以在上面的配置中,它有appSettingsConnectionStringKey参数.自定义提供程序中的代码读取appSettingsConnectionStringKey值'MONGOLAB_URL',然后使用它来读取ConfigurationManager.AppSettings ["MONGOLAB_URL"],显然,必须匹配上面的appsetting Key名称.
[1]:https://github.com/osuritz
[2]:https://github.com/osuritz/MongoDB.Web/commit/b1e9534023ca8cb2e74eb1adbdcb1cd7dd693efa
归档时间: |
|
查看次数: |
883 次 |
最近记录: |