The current program I am working on is for a Registration page for a shopping cart, I have setup a SQL Server with tables to allow data to be recorded as
- UserName,
- Email,
- Password all are set a
Nvarchar(max).
The version of the .NET Framework is 4.5 and I am using VS 2012 and am coding in C#, and the server is an SQL Server instance KENSULLIVAN-PC\KSSQL using integrated Windows Authentication.
So far, I have been able to run the registration page to the point where it will save a cookie of the information but, not send any information to the tables in SQL Server.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
public partial class Account_Register : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
RegisterUser.ContinueDestinationPageUrl = Request.QueryString["ReturnUrl"];
}
//Submit button for user registration information
protected void RegisterUser_CreatedUser(object sender, EventArgs e)
{
int TheUserID = 5000;
SqlConnection conn = new SqlConnection("Server=KENSULLIVAN-PC/KSSQL;Database=GroupProject; Integrated Security=True");
//INSERT command for values to be updated or added to the Database
SqlCommand comm = new SqlCommand("INSERT INTO RegUser (UserName, Email, Password) VALUES (@UserName, @Email, @Password)", conn);
comm.Parameters.Add("@UserName", System.Data.SqlDbType.NVarChar, 100);
comm.Parameters["@UserName"].Value = RegisterUser.UserName;
comm.Parameters.Add("@Email", System.Data.SqlDbType.NVarChar, 100);
comm.Parameters["@Email"].Value = RegisterUser.Email;
comm.Parameters.Add("@Password", System.Data.SqlDbType.NVarChar, 100);
comm.Parameters["@Password"].Value = RegisterUser.Password;
try
{
conn.Open();
comm.ExecuteNonQuery();
Response.Redirect("~/LoggedIn.aspx");
}
catch
{
//ErrorDB.Text = "Error Submitting, Try Again";
}
finally
{
conn.Close();
}
FormsAuthentication.SetAuthCookie(RegisterUser.UserName, false /* createPersistentCookie */);
string continueUrl = RegisterUser.ContinueDestinationPageUrl;
if (String.IsNullOrEmpty(continueUrl))
{
continueUrl = "~/LoggedIn.aspx";
}
Response.Redirect(continueUrl);
}
}
What should I be doing differently, what do you notice that is not really recommended?
Thank you, Kenneth