Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="Login.aspx.cs" Inherits="UW_Final_project.WebForm2" %>
- <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
- <script runat="server">
- protected void btnLogin_Click(object sender, EventArgs e){
- System.Data.SqlClient.SqlConnection objCon = new System.Data.SqlClient.SqlConnection();
- try
- {
- // define connection parameters to SQLServer
- objCon.ConnectionString = @"Data Source=.;Initial Catalog=AdvWebDevProject;Integrated Security=True;MultipleActiveResultSets=True;Application Name=EntityFramework";
- System.Data.SqlClient.SqlCommand objCmd = new System.Data.SqlClient.SqlCommand();
- objCmd.Connection = objCon;
- objCmd.CommandType = System.Data.CommandType.StoredProcedure;
- objCmd.CommandText = "pSelLoginIdByLoginAndPassword";
- // input parameter @StudentLogin
- System.Data.SqlClient.SqlParameter objP1 = new System.Data.SqlClient.SqlParameter();
- objP1.Direction = System.Data.ParameterDirection.Input;
- objP1.DbType = System.Data.DbType.String;
- objP1.Size = 50;
- objP1.ParameterName = "@StudentLogin";
- objP1.Value = tbUsername.Text;
- objCmd.Parameters.Add(objP1);
- // input parameter @StudentPassword
- System.Data.SqlClient.SqlParameter objP2 = new System.Data.SqlClient.SqlParameter();
- objP2.Direction = System.Data.ParameterDirection.Input;
- objP2.DbType = System.Data.DbType.String;
- objP2.Size = 50;
- objP2.ParameterName = "@StudentPassword";
- objP2.Value = tbPassword.Text;
- objCmd.Parameters.Add(objP2);
- // Output Parameters
- System.Data.SqlClient.SqlParameter objP3 = new System.Data.SqlClient.SqlParameter();
- objP3.ParameterName = "@StudentId";
- objP3.SqlDbType = System.Data.SqlDbType.Int;
- objP3.Direction = System.Data.ParameterDirection.Output;
- objCmd.Parameters.Add(objP3);
- // open the connection and execute SQL command
- objCon.Open();
- objCmd.ExecuteNonQuery();
- string StudentId = objP3.Value.ToString();
- Response.Write("Your Id = " + StudentId);
- // user feedback
- Response.Write("Your account has been created");
- HttpCookie cookie = new HttpCookie("StudentID");
- cookie["ID"] = StudentId;
- Response.Cookies.Add(cookie);
- }
- finally { objCon.Close(); } // clean up
- }
- </script>
- </asp:Content>
- <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
- <label>Username: </label>
- <asp:TextBox ID="tbUsername" runat="server"></asp:TextBox><br /><br />
- <label>Password: </label>
- <asp:TextBox ID="tbPassword" runat="server"></asp:TextBox><br /><br />
- <asp:Button ID="btnSubmitRequest" runat="server" Text="Request Access" OnClick="btnLogin_Click" /><br />
- </asp:Content>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement