simplemembership

Cannot insert the value NULL into column 'RoleId' (mvc4 simple membership)

纵然是瞬间 提交于 2019-12-02 16:00:57
问题 I noticed that someone else has faced the same problem such as Cannot insert the value NULL into column 'UserId' but it should be caused by different reasons. The problem can be simplified like this: UsersContext _usersContext = new UsersContext(); ... var usersInRole = new UsersInRole() { RoleId = 3, UserId = 1 }; _usersContext.UsersInRoles.Add(usersInRole); _usersContext.SaveChanges(); The last line of code threw an exception "An error occurred while updating the entries. See the inner

Cannot insert the value NULL into column 'RoleId' (mvc4 simple membership)

ぐ巨炮叔叔 提交于 2019-12-02 13:19:46
I noticed that someone else has faced the same problem such as Cannot insert the value NULL into column 'UserId' but it should be caused by different reasons. The problem can be simplified like this: UsersContext _usersContext = new UsersContext(); ... var usersInRole = new UsersInRole() { RoleId = 3, UserId = 1 }; _usersContext.UsersInRoles.Add(usersInRole); _usersContext.SaveChanges(); The last line of code threw an exception "An error occurred while updating the entries. See the inner exception for details." , and the InnerException was saying the same thing "An error occurred while

A Custom Membership Provider *Without* a Database?

守給你的承諾、 提交于 2019-12-02 12:30:13
I've been looking around various SO questions, blog posts, and so forth regarding the changes to membership providers in MVC 4. While I like many of the changes and the simplification of things (particularly the out-of-the-box external login support), I'm as yet unable to find one seemingly-simple thing... How can I override the membership/role provider with a custom one that uses another data source? I don't want to replace WebSecurity or anything that drastic, since it handles all of the things I want it to handle. (Cookie management, for example.) I don't want to do anything that will break

MVC app getting stuck on an error after server restart

跟風遠走 提交于 2019-12-02 08:09:26
问题 The scenario is as follows. I start an instance of MVC app to debug it. The app uses simple membership and I log in during this run. Then I go back to VS change something and start the instance again. It doesn't happen really often but sometimes at this moment membership starts acting odd. As the app starts, some action, that is behind [Authorize] attribute (to be exact the attribute is on the controller), is called. However the action fails because WebSecurity.CurrentUserId is equal -1 (the

How can i change the default database for simple membership tables

半城伤御伤魂 提交于 2019-12-01 22:57:35
问题 I would like to ask this quick question about the default simple membership database that comes with asp.net mvc 4.5 internet application , my question is about where does it create its tables when I first create new user does it create its table in the default connection string (LocalDB) ? and what if I changed the default connection string to use a custom MS SQL Express database will that get reflected and those tables will be created in my new database ? i noticed this code in the default

How can i change the default database for simple membership tables

坚强是说给别人听的谎言 提交于 2019-12-01 20:30:00
I would like to ask this quick question about the default simple membership database that comes with asp.net mvc 4.5 internet application , my question is about where does it create its tables when I first create new user does it create its table in the default connection string (LocalDB) ? and what if I changed the default connection string to use a custom MS SQL Express database will that get reflected and those tables will be created in my new database ? i noticed this code in the default account model and in its DbContext class it refers to default connection this was the code there :

SimpleMembershipInitializer won't initialize

你。 提交于 2019-12-01 16:07:15
I am struggling with getting a simplemembership scenario working in my EntityFramework / MVC4 / DatabaseFirst project. I've found plenty of examples for working with code first, but nothing for DB first. The problem I'm encountering is the the InitializeDatabaseConnection is throwing an error ("Unable to find the requested .Net Framework Data Provider. It may not be installed.") The code looks like this : WebSecurity.InitializeDatabaseConnection("DALEntities", "tblContacts1", "ContactID", "EMail", autoCreateTables: true); I am not sure what DataProvider is failing. If I try to trace 'into' the

Seeding data and creating/managing roles in MVC4 - how hard can it be?

a 夏天 提交于 2019-12-01 09:37:30
I'm about to go insane, so I'll try getting some help one more time... I'm using Visual Studio Express 2012 for Web to create an internet project using C# + MVC4 + Razor + Entity Framework + ASP.NET 4.5. I need to do the following: automatically create an "admin" user (who will be authorized all over the site) and then create some user roles. I've read about SimpleMembership, roles and everything all over the web, but nothing seems to give me a straightforward method to make the whole thing work. This is what I've done so far: 1- Created a DataContext class: public class DataContext :

What would be equivalent web.config configuration for “enableSimpleMembership”="true:

拥有回忆 提交于 2019-12-01 06:25:19
问题 What would be equivalent configuration of Membership and Role providers in Web.Config for: <appSettings> <add key="enableSimpleMembership" value="true" /> </appSettings> in ASP.NET MVC 4? 回答1: Equivalent configuration of web.config would be: <appSettings> <add key="enableSimpleMembership" value="false" /><!-- false is default if key is not present --> </appSettings> <connectionStrings> <add name="DefaultConnection" connectionString="..." providerName="System.Data.SqlClient" /> <

Customizing SimpleMembership

烈酒焚心 提交于 2019-11-30 17:41:51
问题 After reading this good BLOG about adding custom data to UserProfile table, I wanted to change it the way that UserProfile table should store default data + another class where all additional info is stored. After creating new project using Interenet application template, I have created two classes: Student.cs [Table("Student")] public class Student { [Key] [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)] public virtual int StudentId { get; set; } public virtual string Name {