{"id":6470,"date":"2014-04-18T06:52:08","date_gmt":"2014-04-18T06:52:08","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/04\/18\/simplemembership-with-custom-database-schema-in-asp-net-mvc-4-collection-of-common-programming-errors-2\/"},"modified":"2014-04-18T06:52:08","modified_gmt":"2014-04-18T06:52:08","slug":"simplemembership-with-custom-database-schema-in-asp-net-mvc-4-collection-of-common-programming-errors-2","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/04\/18\/simplemembership-with-custom-database-schema-in-asp-net-mvc-4-collection-of-common-programming-errors-2\/","title":{"rendered":"SimpleMembership with custom database schema in ASP.NET MVC 4-Collection of common programming errors"},"content":{"rendered":"<p>I want to enable the ASP.NET MVC 4&#8217;s SimpleMembership API to integrate with my own database schema. I have a plain and simple table in my database called <code>Users<\/code> with these fields:<\/p>\n<ul>\n<li><strong>Id<\/strong><\/li>\n<li><strong>Name<\/strong><\/li>\n<li><strong>Password<\/strong><\/li>\n<li><strong>Email<\/strong><\/li>\n<li><strong>IsDeleted<\/strong><\/li>\n<\/ul>\n<p>I have already configured the SimpleMembership API to use my database:<\/p>\n<pre><code>WebSecurity.InitializeDatabaseConnection(\"MyStuff\", \"Users\", \"Id\", \"Name\", autoCreateTables: true);\n<\/code><\/pre>\n<p>And I can insert a user too:<\/p>\n<pre><code>WebSecurity.CreateUserAndAccount(model.UserName, model.Password, \n                                 new \n                                 { \n                                        IsDeleted = false, \n                                        Email = \"sampledata@gmail.com\"                \n                                 });\n<\/code><\/pre>\n<p>However, the Password field (or it&#8217;s hash) is not inserted into the Users table (of course), it inserted into another table called <code>webpages_Membership<\/code> which is created with the <code>InitializeDatabaseConnection<\/code> call and contains a lot of unnecessary information which I don&#8217;t need.<\/p>\n<p>Also, I have other automatically created tables called webpages_OAuthMembership, webpages_Roles and webpages_UsersInRoles which I don&#8217;t need.<\/p>\n<p>I&#8217;ve already tried to set the table generation to false:<\/p>\n<pre><code>WebSecurity.InitializeDatabaseConnection(\"MyStuff\", \"Users\", \"Id\", \"Name\", autoCreateTables: false);\n<\/code><\/pre>\n<p>But in this case the CreateUserAndAccount call will throw an exception because it will not find the webpages_Membership table.<\/p>\n<p>It looks like these tables needed when I want to use the SimpleMembership API.<\/p>\n<p>My question is that: what should I do in a scenario like this when I want only a simple <code>Users<\/code> table and nothing more?<\/p>\n<p>Do I have to write the whole membership handling and the authentication logic (hash code generation, etc.) myself?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I want to enable the ASP.NET MVC 4&#8217;s SimpleMembership API to integrate with my own database schema. I have a plain and simple table in my database called Users with these fields: Id Name Password Email IsDeleted I have already configured the SimpleMembership API to use my database: WebSecurity.InitializeDatabaseConnection(&#8220;MyStuff&#8221;, &#8220;Users&#8221;, &#8220;Id&#8221;, &#8220;Name&#8221;, autoCreateTables: true); And [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-6470","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/6470","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=6470"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/6470\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=6470"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=6470"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=6470"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}