Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9060537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T15:15:18+00:00 2026-06-16T15:15:18+00:00

I am trying to register a user to a role but i am getting

  • 0

I am trying to register a user to a role but i am getting the following error:

No user found was found that has the name "MyName"

I have created an MVC 4 Application using the default template.

I have created a custom membership provider and implemented the CreateUser method as follow

public User CreateUser(User i_userToCreate)
    {

        using (var _db = new Repository())
        {

           User _user = _db.CreateUser(i_userToCreate);
           MembershipUser _membershipUser = new MembershipUser(providerName: "ATWMembershipProvider",
           name: _user.UserName,
           providerUserKey: null,
           email: _user.Email,
           passwordQuestion: "",
           comment: "",
           isApproved: true,
           isLockedOut: false,
           creationDate: DateTime.UtcNow,
           lastLoginDate: DateTime.UtcNow,
           lastActivityDate: DateTime.UtcNow,
           lastPasswordChangedDate: DateTime.UtcNow,
           lastLockoutDate: DateTime.UtcNow);

           return _user;
        }

This is how i configured my web.config

<appSettings>
<add key="enableSimpleMembership" value="false"/>
<add key="autoFormsAuthentication" value="false"/>
</appSettings>
<system.web>
<membership defaultProvider="ATWMembershipProvider">
  <providers>
    <clear/>
    <add name="ATWMembershipProvider" type="AroundTheWorld.Infrastructure.ATWMembershipProvider"
         enablePasswordRetrieval="false"
         ConnetionStringName="Context"
         enablePasswordReset="true"
         requiresQuestionAndAnswer="false"
         equiresUniqueEmail="false"
         maxInvalidPasswordAttempts="5"
         minRequiredPasswordLength="6"
         minRequiredNonalphanumericCharacters="0"
         passwordAttemptWindow="10" applicationName="myApplication" />
  </providers>
</membership>
<roleManager enabled="true" defaultProvider="AspNetSqlRoleProvider">
  <providers>
    <remove name="AspNetSqlRoleProvider" />
    <add name="AspNetSqlRoleProvider" type="WebMatrix.WebData.SimpleRoleProvider, WebMatrix.WebData, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    <!-- note: WebMatrix registers SimpleRoleProvider with name
     'AspNetSqlRoleProvider'. I don't know why but i kept it. -->
  </providers>
</roleManager>

Now the authenticate method is as follow:

 var MembershipProvider = new ATWMembershipProvider();
            User authentictedUser = MembershipProvider.CreateUser(_userToCreate);

            FormsAuthentication.SetAuthCookie(authentictedUser.UserName, true);
            System.Web.Security.Roles.AddUserToRole(authentictedUser.UserName, authentictedUser.Role.Name);
            Session.Add("UserID", authentictedUser.ID);
            Session.Add("UserName", authentictedUser.UserName);

I have already checked the following:

  1. My User as all necessary information
  2. I have registered two roles in App_start “user” , “admin”

but i still getting an error that No user found was found that has the name “MyName”

In asp web form that wasn’t necessary in order to secure a folder based on a role

All i am trying to do is to secure an action inside a controller to a specific “Role”

[Authorize(Roles = "admin")]
    public ActionResult GetAllLocations()
    {
        using (var _db = new Repository())
        {
            return View(_db.GetLocations());
        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T15:15:19+00:00Added an answer on June 16, 2026 at 3:15 pm

    I have fixed the problem…

    The problem was because I implemented only a custom membership provider without a role provider.

    I have followed this blog.

    Basically I have created a class MyOwnRoleProvider which inherits from RoleProvider
    and:

    1. Implemented the method called GetRolesForUser
    2. Implemented the method called GetUsersInRole

    finally I modified my web.config to

    <roleManager defaultProvider="ATWRoleProvider" enabled="true" cacheRolesInCookie="true">
      <providers>
        <clear />
        <add name="ATWRoleProvider" type="AroundTheWorld.Infrastructure.ATWRoleProvider, AroundTheWorld" connectionStringName="Context" />
      </providers>
    </roleManager>
    

    after it I was able to use the following

    [Authorize(Roles="admin")]
    public ActionResult GetAllLocations()
    {
      using (var _db = new Repository())
      {
        return View(_db.GetLocations());
      }
    }
    

    AND

    @if (User.IsInRole("user"))
    

    I hope it will be helpful for someone…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I get this error when trying to register a new user. NoMethodError (undefined method
I'm trying to register a user, with the following query: INSERT INTO Users (Username,
I'm trying to register new server in pgadmin3 with following settings: Name: postgres Host:
The set-up: I have an android application that so far can register a user
I am trying to register the following class using the fluent interface: public class
I have a problem trying to register my own Event/Listener to the event dispatcher.
Using PyFacebook I am trying to register a test user of my site with
Possible Duplicate: Android Emulator - Trouble creating user accounts I'm trying to register a
I'm trying to connect the django.contrib.auth User with my own UserProfile, and I'm getting
I was trying to extend user profile. I founded a few solutions, but the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.