ASP.NET MVC Exception 'The Role Manager feature has not been enabled'
I'm trying to make an ASP.net MVC website. I have setup Roles in the Startup.cs file as follows:
private void CreateRolesAndUsers()
{
ApplicationDbContext context = new ApplicationDbContext();
var roleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(context));
var UserManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(context));
if (!roleManager.RoleExists("SuperAdmin"))
{
// first we create Admin role
var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
role.Name = "SuperAdmin";
roleManager.Create(role);
//Here we create a Admin super user who will maintain the website
var user = new ApplicationUser();
user.UserName = "SuperAdmin";
user.Email = "SuperAdmin@SU.com";
string userPWD = "Password1";
var chkUser = UserManager.Create(user, userPWD);
//Add default User to Role Admin
if (chkUser.Succeeded)
{
var result1 = UserManager.AddToRole(user.Id, "SuperAdmin");
}
}
}
I have verified that the above code successfully adds the roles to the db and I first noticed the roles not working when I tried Roles.IsUserInRole(User.Identity.Name, "SuperAdmin")
I'm trying to controll which roles see certain content in a view and am getting an Exception:
System.Configuration.Provider.ProviderException: 'The Role Manager feature has not been enabled.'
when I try to call the following line in a .cshtml file: @Roles.GetRolesForUser();
ive looked where to enable roleManager in Web.config, but cant find it and it dosent work if i add it under the system.web section
EDIT: adding (>roleManager enabled="true"<) into the following code produces another unhandled exception whenever using IsUserInRole: "System.Web.HttpException: Unable to connect to SQL Server database."
<system.web>
<authentication mode="None"/>
<compilation debug="true" targetFramework="4.7"/>
<httpRuntime targetFramework="4.7"/>
</system.web>
i think i might be simply missing a dependancy or some initalizer but have no clue and none of the other solutions in similar quesions have worked.
asp.net-mvc exception roles user-roles asp.net-roles
add a comment |
I'm trying to make an ASP.net MVC website. I have setup Roles in the Startup.cs file as follows:
private void CreateRolesAndUsers()
{
ApplicationDbContext context = new ApplicationDbContext();
var roleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(context));
var UserManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(context));
if (!roleManager.RoleExists("SuperAdmin"))
{
// first we create Admin role
var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
role.Name = "SuperAdmin";
roleManager.Create(role);
//Here we create a Admin super user who will maintain the website
var user = new ApplicationUser();
user.UserName = "SuperAdmin";
user.Email = "SuperAdmin@SU.com";
string userPWD = "Password1";
var chkUser = UserManager.Create(user, userPWD);
//Add default User to Role Admin
if (chkUser.Succeeded)
{
var result1 = UserManager.AddToRole(user.Id, "SuperAdmin");
}
}
}
I have verified that the above code successfully adds the roles to the db and I first noticed the roles not working when I tried Roles.IsUserInRole(User.Identity.Name, "SuperAdmin")
I'm trying to controll which roles see certain content in a view and am getting an Exception:
System.Configuration.Provider.ProviderException: 'The Role Manager feature has not been enabled.'
when I try to call the following line in a .cshtml file: @Roles.GetRolesForUser();
ive looked where to enable roleManager in Web.config, but cant find it and it dosent work if i add it under the system.web section
EDIT: adding (>roleManager enabled="true"<) into the following code produces another unhandled exception whenever using IsUserInRole: "System.Web.HttpException: Unable to connect to SQL Server database."
<system.web>
<authentication mode="None"/>
<compilation debug="true" targetFramework="4.7"/>
<httpRuntime targetFramework="4.7"/>
</system.web>
i think i might be simply missing a dependancy or some initalizer but have no clue and none of the other solutions in similar quesions have worked.
asp.net-mvc exception roles user-roles asp.net-roles
UPDATE: for the time being, I've found a workaround. by using "this.User.IsInRole("SuperAdmin")" I get a working return value. but the above issue still doesn't work.
– Wboston
Nov 19 '18 at 18:10
add a comment |
I'm trying to make an ASP.net MVC website. I have setup Roles in the Startup.cs file as follows:
private void CreateRolesAndUsers()
{
ApplicationDbContext context = new ApplicationDbContext();
var roleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(context));
var UserManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(context));
if (!roleManager.RoleExists("SuperAdmin"))
{
// first we create Admin role
var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
role.Name = "SuperAdmin";
roleManager.Create(role);
//Here we create a Admin super user who will maintain the website
var user = new ApplicationUser();
user.UserName = "SuperAdmin";
user.Email = "SuperAdmin@SU.com";
string userPWD = "Password1";
var chkUser = UserManager.Create(user, userPWD);
//Add default User to Role Admin
if (chkUser.Succeeded)
{
var result1 = UserManager.AddToRole(user.Id, "SuperAdmin");
}
}
}
I have verified that the above code successfully adds the roles to the db and I first noticed the roles not working when I tried Roles.IsUserInRole(User.Identity.Name, "SuperAdmin")
I'm trying to controll which roles see certain content in a view and am getting an Exception:
System.Configuration.Provider.ProviderException: 'The Role Manager feature has not been enabled.'
when I try to call the following line in a .cshtml file: @Roles.GetRolesForUser();
ive looked where to enable roleManager in Web.config, but cant find it and it dosent work if i add it under the system.web section
EDIT: adding (>roleManager enabled="true"<) into the following code produces another unhandled exception whenever using IsUserInRole: "System.Web.HttpException: Unable to connect to SQL Server database."
<system.web>
<authentication mode="None"/>
<compilation debug="true" targetFramework="4.7"/>
<httpRuntime targetFramework="4.7"/>
</system.web>
i think i might be simply missing a dependancy or some initalizer but have no clue and none of the other solutions in similar quesions have worked.
asp.net-mvc exception roles user-roles asp.net-roles
I'm trying to make an ASP.net MVC website. I have setup Roles in the Startup.cs file as follows:
private void CreateRolesAndUsers()
{
ApplicationDbContext context = new ApplicationDbContext();
var roleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(context));
var UserManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(context));
if (!roleManager.RoleExists("SuperAdmin"))
{
// first we create Admin role
var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
role.Name = "SuperAdmin";
roleManager.Create(role);
//Here we create a Admin super user who will maintain the website
var user = new ApplicationUser();
user.UserName = "SuperAdmin";
user.Email = "SuperAdmin@SU.com";
string userPWD = "Password1";
var chkUser = UserManager.Create(user, userPWD);
//Add default User to Role Admin
if (chkUser.Succeeded)
{
var result1 = UserManager.AddToRole(user.Id, "SuperAdmin");
}
}
}
I have verified that the above code successfully adds the roles to the db and I first noticed the roles not working when I tried Roles.IsUserInRole(User.Identity.Name, "SuperAdmin")
I'm trying to controll which roles see certain content in a view and am getting an Exception:
System.Configuration.Provider.ProviderException: 'The Role Manager feature has not been enabled.'
when I try to call the following line in a .cshtml file: @Roles.GetRolesForUser();
ive looked where to enable roleManager in Web.config, but cant find it and it dosent work if i add it under the system.web section
EDIT: adding (>roleManager enabled="true"<) into the following code produces another unhandled exception whenever using IsUserInRole: "System.Web.HttpException: Unable to connect to SQL Server database."
<system.web>
<authentication mode="None"/>
<compilation debug="true" targetFramework="4.7"/>
<httpRuntime targetFramework="4.7"/>
</system.web>
i think i might be simply missing a dependancy or some initalizer but have no clue and none of the other solutions in similar quesions have worked.
asp.net-mvc exception roles user-roles asp.net-roles
asp.net-mvc exception roles user-roles asp.net-roles
edited Nov 19 '18 at 8:00
Wboston
asked Nov 19 '18 at 7:15
WbostonWboston
11
11
UPDATE: for the time being, I've found a workaround. by using "this.User.IsInRole("SuperAdmin")" I get a working return value. but the above issue still doesn't work.
– Wboston
Nov 19 '18 at 18:10
add a comment |
UPDATE: for the time being, I've found a workaround. by using "this.User.IsInRole("SuperAdmin")" I get a working return value. but the above issue still doesn't work.
– Wboston
Nov 19 '18 at 18:10
UPDATE: for the time being, I've found a workaround. by using "this.User.IsInRole("SuperAdmin")" I get a working return value. but the above issue still doesn't work.
– Wboston
Nov 19 '18 at 18:10
UPDATE: for the time being, I've found a workaround. by using "this.User.IsInRole("SuperAdmin")" I get a working return value. but the above issue still doesn't work.
– Wboston
Nov 19 '18 at 18:10
add a comment |
1 Answer
1
active
oldest
votes
You can do this by reading from the boolean property at:
System.Web.Security.Roles.Enabled
This is a direct read from the enabled attribute of the roleManager element in the web.config:
<configuration>
<system.web>
<roleManager enabled="true" />
</system.web>
</configuration>
For more information, check out this MSDN sample: https://msdn.microsoft.com/en-us/library/aa354509(v=vs.110).aspx
as I said in my comment above, I've tried that and it doesn't work. it takes some time to compile and run, then eventually throws another exception : System.Web.HttpException: 'Unable to connect to SQL Server database.'
– Wboston
Nov 19 '18 at 7:52
Have you verified your SQL connection string..Are you able to connect to SQL server database?
– RemS
Nov 19 '18 at 8:32
let's put it this way, everything works before I tried accessing the roleManager, and with your suggested fix, I'd have to recreate and reconnect to the database... that doesn't quite make sense, but thanks for your tip
– Wboston
Nov 19 '18 at 18:05
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53369899%2fasp-net-mvc-exception-the-role-manager-feature-has-not-been-enabled%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can do this by reading from the boolean property at:
System.Web.Security.Roles.Enabled
This is a direct read from the enabled attribute of the roleManager element in the web.config:
<configuration>
<system.web>
<roleManager enabled="true" />
</system.web>
</configuration>
For more information, check out this MSDN sample: https://msdn.microsoft.com/en-us/library/aa354509(v=vs.110).aspx
as I said in my comment above, I've tried that and it doesn't work. it takes some time to compile and run, then eventually throws another exception : System.Web.HttpException: 'Unable to connect to SQL Server database.'
– Wboston
Nov 19 '18 at 7:52
Have you verified your SQL connection string..Are you able to connect to SQL server database?
– RemS
Nov 19 '18 at 8:32
let's put it this way, everything works before I tried accessing the roleManager, and with your suggested fix, I'd have to recreate and reconnect to the database... that doesn't quite make sense, but thanks for your tip
– Wboston
Nov 19 '18 at 18:05
add a comment |
You can do this by reading from the boolean property at:
System.Web.Security.Roles.Enabled
This is a direct read from the enabled attribute of the roleManager element in the web.config:
<configuration>
<system.web>
<roleManager enabled="true" />
</system.web>
</configuration>
For more information, check out this MSDN sample: https://msdn.microsoft.com/en-us/library/aa354509(v=vs.110).aspx
as I said in my comment above, I've tried that and it doesn't work. it takes some time to compile and run, then eventually throws another exception : System.Web.HttpException: 'Unable to connect to SQL Server database.'
– Wboston
Nov 19 '18 at 7:52
Have you verified your SQL connection string..Are you able to connect to SQL server database?
– RemS
Nov 19 '18 at 8:32
let's put it this way, everything works before I tried accessing the roleManager, and with your suggested fix, I'd have to recreate and reconnect to the database... that doesn't quite make sense, but thanks for your tip
– Wboston
Nov 19 '18 at 18:05
add a comment |
You can do this by reading from the boolean property at:
System.Web.Security.Roles.Enabled
This is a direct read from the enabled attribute of the roleManager element in the web.config:
<configuration>
<system.web>
<roleManager enabled="true" />
</system.web>
</configuration>
For more information, check out this MSDN sample: https://msdn.microsoft.com/en-us/library/aa354509(v=vs.110).aspx
You can do this by reading from the boolean property at:
System.Web.Security.Roles.Enabled
This is a direct read from the enabled attribute of the roleManager element in the web.config:
<configuration>
<system.web>
<roleManager enabled="true" />
</system.web>
</configuration>
For more information, check out this MSDN sample: https://msdn.microsoft.com/en-us/library/aa354509(v=vs.110).aspx
answered Nov 19 '18 at 7:26
RemSRemS
1548
1548
as I said in my comment above, I've tried that and it doesn't work. it takes some time to compile and run, then eventually throws another exception : System.Web.HttpException: 'Unable to connect to SQL Server database.'
– Wboston
Nov 19 '18 at 7:52
Have you verified your SQL connection string..Are you able to connect to SQL server database?
– RemS
Nov 19 '18 at 8:32
let's put it this way, everything works before I tried accessing the roleManager, and with your suggested fix, I'd have to recreate and reconnect to the database... that doesn't quite make sense, but thanks for your tip
– Wboston
Nov 19 '18 at 18:05
add a comment |
as I said in my comment above, I've tried that and it doesn't work. it takes some time to compile and run, then eventually throws another exception : System.Web.HttpException: 'Unable to connect to SQL Server database.'
– Wboston
Nov 19 '18 at 7:52
Have you verified your SQL connection string..Are you able to connect to SQL server database?
– RemS
Nov 19 '18 at 8:32
let's put it this way, everything works before I tried accessing the roleManager, and with your suggested fix, I'd have to recreate and reconnect to the database... that doesn't quite make sense, but thanks for your tip
– Wboston
Nov 19 '18 at 18:05
as I said in my comment above, I've tried that and it doesn't work. it takes some time to compile and run, then eventually throws another exception : System.Web.HttpException: 'Unable to connect to SQL Server database.'
– Wboston
Nov 19 '18 at 7:52
as I said in my comment above, I've tried that and it doesn't work. it takes some time to compile and run, then eventually throws another exception : System.Web.HttpException: 'Unable to connect to SQL Server database.'
– Wboston
Nov 19 '18 at 7:52
Have you verified your SQL connection string..Are you able to connect to SQL server database?
– RemS
Nov 19 '18 at 8:32
Have you verified your SQL connection string..Are you able to connect to SQL server database?
– RemS
Nov 19 '18 at 8:32
let's put it this way, everything works before I tried accessing the roleManager, and with your suggested fix, I'd have to recreate and reconnect to the database... that doesn't quite make sense, but thanks for your tip
– Wboston
Nov 19 '18 at 18:05
let's put it this way, everything works before I tried accessing the roleManager, and with your suggested fix, I'd have to recreate and reconnect to the database... that doesn't quite make sense, but thanks for your tip
– Wboston
Nov 19 '18 at 18:05
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53369899%2fasp-net-mvc-exception-the-role-manager-feature-has-not-been-enabled%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
UPDATE: for the time being, I've found a workaround. by using "this.User.IsInRole("SuperAdmin")" I get a working return value. but the above issue still doesn't work.
– Wboston
Nov 19 '18 at 18:10