Create a login system using config file using .net web aplication
LoginPage.aspx page
This below page used for the Textbox and password field
<h3 class="bg-primary text-white">Login Here</h3> <table class="table table-hover"> <tr><td> <asp:TextBox ID="TextBox1" runat="server" placeholder="User Name"></asp:TextBox> </td></tr> <tr><td> <asp:TextBox ID="TextBox2" runat="server" placeholder="Password" TextMode="Password"></asp:TextBox> </td></tr> <tr><td> <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /> </td></tr> </table>
web config file
<configuration> <system.web> <compilation debug="true" targetFramework="4.6.1"/> <httpRuntime targetFramework="4.6.1"/> <!-- THIS IS THE MAIN CODE WHICH IS MOST IMPORTANT --> <authentication mode="Forms"> <forms defaultUrl="~/TravelDetailsInsert.aspx" loginUrl="~/LoginPage.aspx"> <credentials passwordFormat="Clear"> <user name="admin" password="admin"/> <user name="rumman" password="rumman"/> </credentials> </forms> </authentication> <!-- END OF FOCUS HERE --> </system.web> <!-- THE BELOW CODE IS IMPORTNT IF YOU WANT TO USE THE VALIDATION CONTROL --> <appSettings> <add key="ValidationSettings:UnObtrusiveValidationMode" value="None"/> </appSettings> <!-- THE BELOW CODE IS USED TO CONNECT WITH THE DATA BASE SQL SERVER--> <connectionStrings> <add name="constring" connectionString="Data Source = intvmsql01; Initial Catalog = DB02TEST01; User ID= pj02test01; password=tcstvm;"/> </connectionStrings> <system.codedom> <compilers> <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.8.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701"/> <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.8.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+"/> </compilers> </system.codedom> </configuration>
file name: LoginPage.aspx.cs
The below using System.Web.Security;
is important to execute the below code
using System.Web.Security;
protected void Button1_Click(object sender, EventArgs e) { if(FormsAuthentication.Authenticate(TextBox1.Text, TextBox2.Text)) { FormsAuthentication.RedirectFromLoginPage(TextBox1.Text, false); } else { Label3.Text = "Invalid Credentials entered."; } //if (TextBox1.Text == "admin" && TextBox2.Text == "password") //{ // Response.Redirect("TravelDetailsInsert.aspx"); // Label3.Text = Convert.ToString("Successfully Login"); //} //else //{ // Response.Write("<script> alert('User Name or Password is wrong') </script>"); // Label3.Text = Convert.ToString("UnSuccessfully Login"); //} }