InterviewSolution
| 1. |
Write A Program To Create Login Form? |
|
Answer» The following example demonstrates how to use a Login Control to provide a USER interface to LOG on to a Web site With sql server database. VB : Imports System. Data , Imports System.Data.SqlClient and Imports System.Web.Configuration , C# : using System. Data; , using System.Data.SqlClient; and using System.Web.Configuration; 1. xml FILE or web. Config provider Name="System.Data.SqlClient"/> 2. how-to-login-with-sql-server-c.aspx (Design Page) <%@ Page LANGUAGE="C#" AutoEventWireup="true" Code File="how- to-login-with-sql-server-c.aspx.cs" Inherits="how_to_login_with_sql_server_c" %> Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1- transitional.dtd"> how to login with sql server database: Back Color="#FFFBD6" Border Color="#FFDFAD" Border Padding="4" Border Style="Solid" Border Width="1px" Font- Names="Verdana" Font-Size="0.8em" Fore Color="#333333" On Authenticate="Login1_Authenticate" TestLayout="TextOnTop" Width="293px" Height="172px"> Bold="True" Font-Size="0.9em" Fore Color="White" /> Fore Color="Black" /> Border Color="#CC9966" Border Style="Solid" Border Width="1px" Font-Names="Verdana" Font-Size="0.8em" Fore Color="#990000" /> 3. how-to-login-with-sql-server-c.aspx.cs (Code Behind C# Language) using System; using System.Collections; using System. Configuration; using System. Data; using System.Linq; using System. Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System. Data; using System.Data.SqlClient; using System.Web.Configuration; public PARTIAL class how_to_login_with_sql_server_c : System.Web.UI. Page { protected void Login1_Authenticate(object sender, AuthenticateEventArgs e) { string username = Login1.UserName; string pwd = Login1.Password; string str Conn; str Conn = WebConfigurationManager.ConnectionStrings ["ConnectionASPX"].Connection String; SqlConnection Conn = new SqlConnection(strConn); Conn. Open (); String sqlUserName; SqlUserName = "SELECT Username, Password FROM Username "; SqlUserName += " WHERE (Username ='" + username + "')"; SqlUserName += " AND (Password ='" + pwd + "')"; SqlCommand com = new SqlCommand (sqlUserName, Conn); String Current Name; Current Name = (string) com.ExecuteScalar (); if (Current Name != null) { Session["User Authentication"] = username; Session. Timeout = 1; Response.Redirect("how-to-StartPage.aspx"); } else { Session["User Authentication"] = ""; } } } The following example demonstrates how to use a Login Control to provide a user interface to log on to a Web site With sql server database. VB : Imports System. Data , Imports System.Data.SqlClient and Imports System.Web.Configuration , C# : using System. Data; , using System.Data.SqlClient; and using System.Web.Configuration; 1. xml file or web. Config provider Name="System.Data.SqlClient"/> 2. how-to-login-with-sql-server-c.aspx (Design Page) <%@ Page Language="C#" AutoEventWireup="true" Code File="how- to-login-with-sql-server-c.aspx.cs" Inherits="how_to_login_with_sql_server_c" %> Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1- transitional.dtd"> how to login with sql server database: Back Color="#FFFBD6" Border Color="#FFDFAD" Border Padding="4" Border Style="Solid" Border Width="1px" Font- Names="Verdana" Font-Size="0.8em" Fore Color="#333333" On Authenticate="Login1_Authenticate" TestLayout="TextOnTop" Width="293px" Height="172px"> Bold="True" Font-Size="0.9em" Fore Color="White" /> Fore Color="Black" /> Border Color="#CC9966" Border Style="Solid" Border Width="1px" Font-Names="Verdana" Font-Size="0.8em" Fore Color="#990000" /> 3. how-to-login-with-sql-server-c.aspx.cs (Code Behind C# Language) using System; using System.Collections; using System. Configuration; using System. Data; using System.Linq; using System. Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System. Data; using System.Data.SqlClient; using System.Web.Configuration; public partial class how_to_login_with_sql_server_c : System.Web.UI. Page { protected void Login1_Authenticate(object sender, AuthenticateEventArgs e) { string username = Login1.UserName; string pwd = Login1.Password; string str Conn; str Conn = WebConfigurationManager.ConnectionStrings ["ConnectionASPX"].Connection String; SqlConnection Conn = new SqlConnection(strConn); Conn. Open (); String sqlUserName; SqlUserName = "SELECT Username, Password FROM Username "; SqlUserName += " WHERE (Username ='" + username + "')"; SqlUserName += " AND (Password ='" + pwd + "')"; SqlCommand com = new SqlCommand (sqlUserName, Conn); String Current Name; Current Name = (string) com.ExecuteScalar (); if (Current Name != null) { Session["User Authentication"] = username; Session. Timeout = 1; Response.Redirect("how-to-StartPage.aspx"); } else { Session["User Authentication"] = ""; } } } |
|