In the past few days, I have been practicing the musicstore project. But when I create a project role to complete different access permissions on the page, the problem arises,
However, the solution has just been solved. The following is a summary:
Problem:
When creating a project, you certainly do not want all users to access your page at will. Generally, only Administrators can access the page at the background.
How can I set this administrator role? Open the project and click "project"> "Asp.net configuration". The browser is automatically opened to start the website.
Management tools.
In fact, this network management tool is a graphical web. config file controller. All your graphical operations will be reflected in the project's
In the Web. config file. Click "security" to create a management role. However, the problem is that my application cannot open this role.
"Security" option.
Solution:
Next, I started to find out the cause of the problem. I found that using network management tools to create users, creating roles is actually calling the project.
The database files in the file are operated. However, this is not detailed in the musicstore Project Guide.
As shown above, step-by-step operations won't work.
I have re-created an mvc3 project. Remember to create an Internet project instead of empty. By default, an Asp.net number is created for the project.
To store personal account information, and then enable this network management tool again, which is "safe" option is useful.
I found some differences between my project and the web. config file in the new project.
The connectionstrings name of my project is musicstoreentities. But the program
The default database connection is defaultconnection. When you use the website management tool to create roles and users
The default value is defaultconnection, rather than musicstoreentities.
So my solution is to add a new connection and create a database through the new connection to separately store user information.
<Add name = "defaultconnection" providername = "system. Data. sqlclient"
Connectionstring = "Data Source = (localdb) \ v11.0;
Initial catalog = aspnetdb; Integrated Security = sspi;
Attachdbfilename = | datadirectory | \ aspnetdb. MDF "/>.
After that, the problem still failed to be solved ~
After some hard work, we found that <profile> <membership> <rolemanager>
<Sessionstate> these nodes actually work. Each node has a <providers> subnode.
This is the connectionstringname attribute in it to specify the defaultconnection name)
However, the <profile> node cannot directly call the <providers> subnode.
Connectionstringname. Instead, a defaultprovider attribute is used, and the attribute value is <providers>
The name of the node. In this way, the connectionstringname will be called and then the defaultconnection will be called.
For more information, see <membership>. The detailed code is as follows:
<membership defaultProvider="DefaultMembershipProvider"> <providers> <add connectionStringName="DefaultConnection" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" name="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /> </providers></membership>
My error is that I forgot to add the defaultprovider attribute to the <membership> node. After this is done, it will be smooth.
Use the website management tool. In addition, through this example, I also understand why the database storing the account will generate so many
What code are these tables used to generate them. (This is basically clear)
Do you think the names of many tables correspond to the names of nodes in Web. config.
Now, let's get to it. I hope it can help anyone who just started with MVC.
^_^ Hope to talk with new users more, Sina Weibo: @ pioneer 345