{"id":209,"date":"2021-03-21T12:11:14","date_gmt":"2021-03-21T12:11:14","guid":{"rendered":"https:\/\/wshop.fi\/eng\/?p=209"},"modified":"2021-03-21T12:14:10","modified_gmt":"2021-03-21T12:14:10","slug":"asp-asp-net-forms-authentication-login-control-with-sql-server-using-aspnetdb-mdf","status":"publish","type":"post","link":"https:\/\/wshop.fi\/eng\/asp-asp-net-forms-authentication-login-control-with-sql-server-using-aspnetdb-mdf\/","title":{"rendered":"Asp.Net Forms Authentication Login Control With SQL Server Using aspnetdb.mdf \u2013 ASP.NET Membership"},"content":{"rendered":"\n<p>This tutorial will show you how to make the ASP.NET forms authentication work with SQL Server using the provided ASPNETDB.MDF file.&nbsp; Then it will show you how to properly configure your web.config file to use it.<\/p>\n\n\n\n<p>*Note \u2013 This tutorial will help if you are having trouble getting your forms based authentication to work in a shared hosting environment.<\/p>\n\n\n\n<p>Visual Studio provides an excellent way to manage user authentication. ASP.NET forms authentication will require the user to enter a username and password. ASP.NET creates all of this for you.&nbsp; You can either do this with the login control, or choose the premade template when creating your site which includes the login control.&nbsp; It also has the redirect already set up (redirects user to login screen if not logged in or trying to access a restricted area).&nbsp; It stores the information in an ASPNETDB.MDF database file.&nbsp; The ASPNETDB.MDF file contains both the schema and data. You can create roles and access rules using this provided ASPNET.MDF file. You will use the, \u201cASP.NET Configuration\u201d to make the access rules and roles.<\/p>\n\n\n\n<p>Some of what the asp.net forms authentication can do.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Creating new users and passwords.<\/li><li>Store membership info<\/li><li>Managing passwords, which includes creating, changing, and resetting.<\/li><\/ul>\n\n\n\n<p>The ASPNETDB.MDF file is added to your project and is in the App_Data folder.<\/p>\n\n\n\n<p>*Note \u2013&nbsp;<strong>You may need to run \u201cASP.NET Configuration\u201d and refresh before the file will show up. You may also need to create a role and\/or username. Roles are created when&nbsp;\u201cASP.NET Configuration\u201d is run. You can register \/ creates a user account by running Register.ASPX in Visual Studio. It\u2019s under the \u201cAccount\u201d folder.&nbsp;<\/strong><\/p>\n\n\n\n<p>Some people have problems when trying to upload ASPNETDB.MDF file to their server and getting it to work properly, especially with shared hosting.&nbsp; Since the schema and data are so useful in the ASPNETDB.MDF file we\u2019ll move it over to our SQL Server database.<\/p>\n\n\n\n<p>Start by choosing the ASP.NET Web Site template in Visual Studio.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"980\" height=\"600\" src=\"https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/asp-net-login-template.png\" alt=\"\" class=\"wp-image-210\" srcset=\"https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/asp-net-login-template.png 980w, https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/asp-net-login-template-300x184.png 300w, https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/asp-net-login-template-768x470.png 768w, https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/asp-net-login-template-696x426.png 696w, https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/asp-net-login-template-686x420.png 686w\" sizes=\"auto, (max-width: 980px) 100vw, 980px\" \/><figcaption>asp-net-login-template<\/figcaption><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">The ASPNET.MDF File<\/h2>\n\n\n\n<p><strong>*To see the ASPNETDB.MDF file in your solution explorer, database explorer, or server explorer you may have to first run, \u201cASP.NET Configuration.\u201d<\/strong>\u00a0To do this, click ASP.NET Configuration in your Visual Studio menu under Websites > ASP.NET Configuration.\u00a0 Then refresh.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/visual-studio-login-aspnetdb-mdf.png\" alt=\"\" class=\"wp-image-211\" width=\"765\" height=\"445\"\/><figcaption>visual-studio-login-aspnetdb-mdf<\/figcaption><\/figure><\/div>\n\n\n\n<p>After running ASP.NET Configuration in Visual Studio in this screen will show in the browser. This is the ASP.net Web Site Administration Tool and is where Roles and Access Rules are managed.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"728\" height=\"416\" src=\"https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/asp-net-web-site-administration-tool1.png\" alt=\"\" class=\"wp-image-212\" srcset=\"https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/asp-net-web-site-administration-tool1.png 728w, https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/asp-net-web-site-administration-tool1-300x171.png 300w, https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/asp-net-web-site-administration-tool1-696x398.png 696w\" sizes=\"auto, (max-width: 728px) 100vw, 728px\" \/><figcaption>asp-net-web-site-administration-tool<\/figcaption><\/figure><\/div>\n\n\n\n<p>Next right click the ASPNETDB.MDF file in your database explorer, server explorer, Solution Explorer. Select the option \u201cPublish to Provider.\u201d This creates a SQL script we can use in our SQL Server Management studio to recreate our database.<\/p>\n\n\n\n<p>*Note &#8211; This is done differently depending on the version of Visual Studio used. &nbsp;Below I will show a couple of ways.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">ASPNET.MDF in Visual Studio Express<\/h2>\n\n\n\n<p>Below is via \u201cDatabase Explorer\u201d in an\u00a0<em>express version<\/em>\u00a0of Visual Studio.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"728\" height=\"416\" src=\"https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/visual-studio-login-aspnetdb-mdf-publish-provider-1.png\" alt=\"\" class=\"wp-image-214\" srcset=\"https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/visual-studio-login-aspnetdb-mdf-publish-provider-1.png 728w, https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/visual-studio-login-aspnetdb-mdf-publish-provider-1-300x171.png 300w, https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/visual-studio-login-aspnetdb-mdf-publish-provider-1-696x398.png 696w\" sizes=\"auto, (max-width: 728px) 100vw, 728px\" \/><figcaption>visual-studio-login-aspnetdb-mdf-publish-provider<\/figcaption><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">ASPNET.MDF is Visual Studio<\/h2>\n\n\n\n<p>In a full version of Visual Studio, \u00a0go under the \u201cApp_Data\u201d folder, right click on the ASPNETDB.MDF file and click \u201cInclude In Project.\u201d<\/p>\n\n\n\n<p><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"728\" height=\"455\" src=\"https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/asp-net-login-include-aspnetmdf-in-project.png\" alt=\"\" class=\"wp-image-215\" srcset=\"https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/asp-net-login-include-aspnetmdf-in-project.png 728w, https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/asp-net-login-include-aspnetmdf-in-project-300x188.png 300w, https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/asp-net-login-include-aspnetmdf-in-project-696x435.png 696w, https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/asp-net-login-include-aspnetmdf-in-project-672x420.png 672w\" sizes=\"auto, (max-width: 728px) 100vw, 728px\" \/><\/figure><\/div>\n\n\n\n<p>The icon for the\u00a0ASPNETDB.MDF should turn a yellow\/golden color. Double click the file. \u00a0That should open the \u201cServer Explorer,\u201d where you can then right click the ASPNET.MDF file that is in the \u201cServer Explorer,\u201d select the option \u201cPublish to Provider.\u201d<\/p>\n\n\n\n<p><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"728\" height=\"455\" src=\"https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/asp-net-login-publish-to-provider-visual-studio-1.png\" alt=\"\" class=\"wp-image-217\" srcset=\"https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/asp-net-login-publish-to-provider-visual-studio-1.png 728w, https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/asp-net-login-publish-to-provider-visual-studio-1-300x188.png 300w, https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/asp-net-login-publish-to-provider-visual-studio-1-696x435.png 696w, https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/asp-net-login-publish-to-provider-visual-studio-1-672x420.png 672w\" sizes=\"auto, (max-width: 728px) 100vw, 728px\" \/><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Database Publishing Wizard<\/h2>\n\n\n\n<p>After you click \u201cPublish to Provider,\u201d a new window will open, \u201cWelcome to the Database Publishing Wizard.\u201d<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"500\" height=\"450\" src=\"https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/asp-net-visual-studio-database-publishing-wizard1.png\" alt=\"\" class=\"wp-image-218\" srcset=\"https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/asp-net-visual-studio-database-publishing-wizard1.png 500w, https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/asp-net-visual-studio-database-publishing-wizard1-300x270.png 300w, https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/asp-net-visual-studio-database-publishing-wizard1-467x420.png 467w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><figcaption>asp-net-visual-studio-database-publishing-wizard<\/figcaption><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">ASPNET.MDF in Database Publishing Wizard<\/h2>\n\n\n\n<p>Select the ASPNET.MDF file and click next. Make sure, \u201cScript all objects in the selected database\u201d is checked.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/database-publishing-aspnetdb-mdf1.png\" alt=\"\" class=\"wp-image-219\" width=\"500\" height=\"450\" srcset=\"https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/database-publishing-aspnetdb-mdf1.png 500w, https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/database-publishing-aspnetdb-mdf1-300x270.png 300w, https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/database-publishing-aspnetdb-mdf1-467x420.png 467w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/figure><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p>Now select the destination of the output for the script that will be created, and click next. Make note of where you are saving your file.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"500\" height=\"450\" src=\"https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/database-publishing-aspnetdb-mdf-sql-output-location1.png\" alt=\"\" class=\"wp-image-220\" srcset=\"https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/database-publishing-aspnetdb-mdf-sql-output-location1.png 500w, https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/database-publishing-aspnetdb-mdf-sql-output-location1-300x270.png 300w, https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/database-publishing-aspnetdb-mdf-sql-output-location1-467x420.png 467w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><figcaption>database-publishing-aspnetdb-mdf-sql-output-location<\/figcaption><\/figure><\/div>\n\n\n\n<p>Select publishing options\u2026 Click next.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"500\" height=\"450\" src=\"https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/aspnetdb-mdf-options-settings1.png\" alt=\"\" class=\"wp-image-221\" srcset=\"https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/aspnetdb-mdf-options-settings1.png 500w, https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/aspnetdb-mdf-options-settings1-300x270.png 300w, https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/aspnetdb-mdf-options-settings1-467x420.png 467w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/figure><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p>Now review and click, Finish.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"500\" height=\"450\" src=\"https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/aspnetdb-mdf-database-sql-script-review1.png\" alt=\"\" class=\"wp-image-222\" srcset=\"https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/aspnetdb-mdf-database-sql-script-review1.png 500w, https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/aspnetdb-mdf-database-sql-script-review1-300x270.png 300w, https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/aspnetdb-mdf-database-sql-script-review1-467x420.png 467w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><figcaption>aspnetdb-mdf-database-sql-script-review<\/figcaption><\/figure><\/div>\n\n\n\n<p>You should see a screen like below. Be patient, it may take a few minutes to complete. Once finished, click close.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"500\" height=\"450\" src=\"https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/database-publishing-aspnetdb-mdf-progress-finished1.png\" alt=\"\" class=\"wp-image-223\" srcset=\"https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/database-publishing-aspnetdb-mdf-progress-finished1.png 500w, https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/database-publishing-aspnetdb-mdf-progress-finished1-300x270.png 300w, https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/database-publishing-aspnetdb-mdf-progress-finished1-467x420.png 467w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><figcaption>database-publishing-aspnetdb-mdf-progress-finished<\/figcaption><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Using SQL Server Management Studio to run the ASPNET.sql Script<\/h2>\n\n\n\n<p>Now open SQL Server management Studio. Create a new blank database\u2026..<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"728\" height=\"388\" src=\"https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/sql-server-management-studio-create-new-database.png\" alt=\"\" class=\"wp-image-224\" srcset=\"https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/sql-server-management-studio-create-new-database.png 728w, https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/sql-server-management-studio-create-new-database-300x160.png 300w, https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/sql-server-management-studio-create-new-database-696x371.png 696w\" sizes=\"auto, (max-width: 728px) 100vw, 728px\" \/><figcaption>sql-server-management-studio-create-new-database<\/figcaption><\/figure><\/div>\n\n\n\n<p>New Database:<\/p>\n\n\n\n<p><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"704\" height=\"632\" src=\"https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/New-Database.png\" alt=\"\" class=\"wp-image-225\" srcset=\"https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/New-Database.png 704w, https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/New-Database-300x269.png 300w, https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/New-Database-696x625.png 696w, https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/New-Database-468x420.png 468w\" sizes=\"auto, (max-width: 704px) 100vw, 704px\" \/><figcaption>New-Database<\/figcaption><\/figure><\/div>\n\n\n\n<p>Double click on the\u00a0<strong>sql (ASPNET.MDF.sql)\u00a0<\/strong>\u00a0file you just created to open it in SQL Server Management Studio.\u00a0<strong>*It may look like\u00a0<strong>ASPNET.MDF.\u00a0<\/strong><\/strong>The .sql is \u00a0a\u00a0<strong>hidden<\/strong>\u00a0file extension.<strong>Make sure the new database you just created is selected.\u00a0<\/strong>Execute the aspnetdb.mdf sql file you just loaded (the tab will need to be selected in SQL Server Management Studio). You are executing this script so that it will create the necessary tables, relationships, etc., into your new SQL Server database.\u00a0 You can now use this for your asp.net login.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"728\" height=\"388\" src=\"https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/sql-server-management-studio-script-execute.png\" alt=\"\" class=\"wp-image-226\" srcset=\"https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/sql-server-management-studio-script-execute.png 728w, https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/sql-server-management-studio-script-execute-300x160.png 300w, https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/sql-server-management-studio-script-execute-696x371.png 696w\" sizes=\"auto, (max-width: 728px) 100vw, 728px\" \/><figcaption>sql-server-management-studio-script-execute<\/figcaption><\/figure><\/div>\n\n\n\n<p>After \u00a0execution it will look like below. You should be able to double click on the database you just created on the left and expand.\u00a0<strong>Refresh<\/strong>. Expand the tables folder to see all of the tables the script just created.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"728\" height=\"388\" src=\"https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/sql-server-management-studio-script-post-execution.png\" alt=\"\" class=\"wp-image-227\" srcset=\"https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/sql-server-management-studio-script-post-execution.png 728w, https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/sql-server-management-studio-script-post-execution-300x160.png 300w, https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/sql-server-management-studio-script-post-execution-696x371.png 696w\" sizes=\"auto, (max-width: 728px) 100vw, 728px\" \/><figcaption>sql-server-management-studio-script-post-execution<\/figcaption><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Web.config Connection String<\/h2>\n\n\n\n<p>Almost There! Now that you have your DB setup, all that is left is to configure your web.config file to use the SQL Server Database you just created.<\/p>\n\n\n\n<p>The asp.net login is still setup to use the default connection string of our original aspnet.mdf file.&nbsp; We need to change the connection string to the SQL Server Database we just made. We have 3 separate areas to update,&nbsp;&lt;connectionStrings&gt;,&nbsp;&lt;membership&gt;, and&nbsp;&lt;roleManager&gt;. The connection string needs to be updated to connect to the new database that was just made. Then there are &lt;providers&gt; tags. One is under&lt;membership&gt; and the other under &lt;roleManager&gt;. Update \u201cconnectionStringName\u201d here to the same name as entered in &lt;connectionStrings&gt;.<\/p>\n\n\n\n<p>For the connectionString, the \u201cData Source\u201d should be the same as what is listed in the \u201cObject Explorer\u201d in SQL Server Management Studio. ID, and Password should be what was used to connect to the Database in&nbsp;&nbsp;SQL Server Management Studio.<\/p>\n\n\n\n<p>See image below. \u00a0The old connection information is commented out with the new information put in.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"728\" height=\"485\" src=\"https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/webconfig-connection-string-aspnet-login-sql-server1-1.png\" alt=\"\" class=\"wp-image-229\" srcset=\"https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/webconfig-connection-string-aspnet-login-sql-server1-1.png 728w, https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/webconfig-connection-string-aspnet-login-sql-server1-1-300x200.png 300w, https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/webconfig-connection-string-aspnet-login-sql-server1-1-696x464.png 696w, https:\/\/wshop.fi\/eng\/wp-content\/uploads\/2021\/03\/webconfig-connection-string-aspnet-login-sql-server1-1-630x420.png 630w\" sizes=\"auto, (max-width: 728px) 100vw, 728px\" \/><figcaption>webconfig-connection-string-aspnet-login-sql-server<\/figcaption><\/figure><\/div>\n\n\n\n<p>Here is sample code for the Web.config:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;configuration>\n  &lt;connectionStrings>\n    &lt;!--&lt;add name=\"ApplicationServices\"\n         connectionString=\"data source=.\\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\\aspnetdb.mdf;User Instance=true\"\n         providerName=\"System.Data.SqlClient\" \/>-->\n      &lt;add name=\"Reports\" connectionString=\"Data Source=YOUR-SQL-DB;Initial Catalog=Reports;Persist Security Info=True;User ID=YOURID;Password=YOURPASSWORD\"\n      providerName=\"System.Data.SqlClient\" \/>\n  &lt;\/connectionStrings>\n \n  &lt;system.web>\n    &lt;compilation debug=\"true\" targetFramework=\"4.0\" \/>\n \n    &lt;authentication mode=\"Forms\">\n      &lt;forms loginUrl=\"~\/Account\/Login.aspx\" timeout=\"2880\" \/>\n    &lt;\/authentication>\n \n    &lt;membership>\n      &lt;providers>\n        &lt;clear\/>\n        &lt;!--&lt;add name=\"AspNetSqlMembershipProvider\" type=\"System.Web.Security.SqlMembershipProvider\" connectionStringName=\"ApplicationServices\"\n             enablePasswordRetrieval=\"false\" enablePasswordReset=\"true\" requiresQuestionAndAnswer=\"false\" requiresUniqueEmail=\"false\"\n             maxInvalidPasswordAttempts=\"5\" minRequiredPasswordLength=\"6\" minRequiredNonalphanumericCharacters=\"0\" passwordAttemptWindow=\"10\"\n             applicationName=\"\/\" \/>-->\n          &lt;add name=\"AspNetSqlMembershipProvider\" type=\"System.Web.Security.SqlMembershipProvider\" connectionStringName=\"Reports\" \n               enablePasswordRetrieval=\"false\" enablePasswordReset=\"true\" requiresQuestionAndAnswer=\"false\" requiresUniqueEmail=\"false\" \n               maxInvalidPasswordAttempts=\"25\" minRequiredPasswordLength=\"6\" minRequiredNonalphanumericCharacters=\"0\" passwordAttemptWindow=\"10\" \n               applicationName=\"\/\"\/>\n      &lt;\/providers>\n    &lt;\/membership>\n \n    &lt;profile>\n      &lt;providers>\n        &lt;clear\/>\n        &lt;add name=\"AspNetSqlProfileProvider\" type=\"System.Web.Profile.SqlProfileProvider\" connectionStringName=\"ApplicationServices\" applicationName=\"\/\"\/>\n      &lt;\/providers>\n    &lt;\/profile>\n \n    &lt;roleManager enabled=\"true\">\n      &lt;providers>\n        &lt;clear \/>\n        &lt;!--&lt;add connectionStringName=\"ApplicationServices\" applicationName=\"\/\"\n          name=\"AspNetSqlRoleProvider\" type=\"System.Web.Security.SqlRoleProvider\" \/>-->\n        &lt;add connectionStringName=\"Reports\" applicationName=\"\/\" name=\"AspNetSqlRoleProvider\" type=\"System.Web.Security.SqlRoleProvider\"\/>\n        &lt;add applicationName=\"\/\" name=\"AspNetWindowsTokenRoleProvider\"\n          type=\"System.Web.Security.WindowsTokenRoleProvider\" \/>\n      &lt;\/providers>\n    &lt;\/roleManager>\n \n  &lt;\/system.web>\n \n  &lt;system.webServer>\n     &lt;modules runAllManagedModulesForAllRequests=\"true\"\/>\n  &lt;\/system.webServer>\n&lt;\/configuration><\/code><\/pre>\n\n\n\n<p>Use Visual Studio to run the Login.aspx file located in the \u201cAccount\u201d folder. You should see a login screen in your browser.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial will show you how to make the ASP.NET forms authentication work with SQL Server using the provided ASPNETDB.MDF file.&nbsp; Then it will show you how to properly configure your web.config file to use it. *Note \u2013 This tutorial will help if you are having trouble getting your forms based authentication to work in [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":192,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":{"0":"post-209","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-uncategorized"},"_links":{"self":[{"href":"https:\/\/wshop.fi\/eng\/wp-json\/wp\/v2\/posts\/209","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wshop.fi\/eng\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wshop.fi\/eng\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wshop.fi\/eng\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wshop.fi\/eng\/wp-json\/wp\/v2\/comments?post=209"}],"version-history":[{"count":2,"href":"https:\/\/wshop.fi\/eng\/wp-json\/wp\/v2\/posts\/209\/revisions"}],"predecessor-version":[{"id":232,"href":"https:\/\/wshop.fi\/eng\/wp-json\/wp\/v2\/posts\/209\/revisions\/232"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wshop.fi\/eng\/wp-json\/wp\/v2\/media\/192"}],"wp:attachment":[{"href":"https:\/\/wshop.fi\/eng\/wp-json\/wp\/v2\/media?parent=209"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wshop.fi\/eng\/wp-json\/wp\/v2\/categories?post=209"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wshop.fi\/eng\/wp-json\/wp\/v2\/tags?post=209"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}