I want to use the role management asp.net, but Visual Studio keeps creating the ASPNETDB.MDF file all the time, and I don’t need this. I already have an existing database file which I want to use instead of the ASPNETDB.MDF. This is mainly for denying unnecessary directory listing for unwanted users.
Thanks in advance.
You can get rid of the ASPNETDB.MDF – an extraneous attached database file, and can store all your security information (users, roles) inside your custom SQL Database.
Follow these simple steps
Step 01 – Create Security Tables in Your SQL Database
First, you need to create tables that will hold ASP.NET security information inside your SQL database. There is a wizard for that.
ASP.NET SQL Server Setup Wizard is located (Windows XP and Windows 2008 Server):
ASP.NET SQL Server Setup Wizard is located (Windows 7 x64) in one of those:
This self-guided wizard is very simple. You pick your SQL Server (usually .\SQLExpress) and desired database and the wizard will create all required tables and objects to handle ASP.NET security inside your custom SQL database.
Step 02 – Generate a Machine Key
Passwords inside security tables are store encrypted. You need to generate and record your unique machine key inside web.config file.
Visit http://aspnetresources.com/tools/machineKey and get a ready unique machine key neatly wraped in a few lines of code, ready for your web.config. Generate your lines and place them inside XML element:
Step03 – Modify Your web.config
Modify your web.config to include membership, roles and profile providers.
Place code similar to these lines bellow inside XML element. Replace word “Your” with an appropriate name, matching your naming conventions.
…
Now you can run ASP.NET Configuration inside Web Developer or Visual Studio and make sure that all new users are created inside your custom database, and not in /App_Data/ASPNETDB.MDF