this is my class code
- namespace SECODMS.Model {
- public class ApplicationUser {
- public string UserName { get ; set; }
- public string FirstName{ get; set; }
- public string LastName { get; set; }
- public string Email { get; set; }
- public string AvatarUrl { get; set; }
- }
-
- public static class AuthHelper {
- public static bool SignIn(string userName, string password) {
- HttpContext.Current.Session["User"] = CreateDefualtUser();
-
- return true;
- }
- public static void SignOut() {
- HttpContext.Current.Session["User"] = null;
- }
- public static bool IsAuthenticated() {
- return GetLoggedInUserInfo() != null;
- }
- public static ApplicationUser GetLoggedInUserInfo()
- {
- return HttpContext.Current.Session["User"] as ApplicationUser;
- }
- private static ApplicationUser CreateDefualtUser() {
- return new ApplicationUser {
-
- UserName ="vvnbnbnb",
- FirstName = "Julia",
- LastName = "Bell",
- Email = "[email protected]",
- AvatarUrl = "~/Content/Photo/Julia_Bell.jpg"
- };
- }
- }
- using System;
- using DevExpress.Web;
- using SECODMS.Model;
- using System.Configuration;
- using System.Data;
- using System.Data.SqlClient;
-
- namespace SECODMS {
- public partial class SignInModule: System.Web.UI.Page
-
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- }
- protected void SignInButton_Click(object sender, EventArgs e) {
-
- FormLayout.FindItemOrGroupByName("GeneralError").Visible = false;
-
- if (ASPxEdit.ValidateEditorsInContainer(this)) {
-
- string mainconn = ConfigurationManager.ConnectionStrings["SECODMSConnectionString"].ConnectionString;
- SqlConnection sqlconn = new SqlConnection(mainconn);
- string sqlquery = "Select * from Users where Username=@Username and Password=@Password";
- SqlCommand sqlcomm = new SqlCommand(sqlquery, sqlconn);
- sqlconn.Open();
- sqlcomm.Parameters.AddWithValue("@Username", UserNameTextBox.Text);
- sqlcomm.Parameters.AddWithValue("@Password", PasswordButtonEdit.Text);
- SqlDataAdapter sda = new SqlDataAdapter(sqlcomm);
- DataTable dt = new DataTable();
- sda.Fill(dt);
- sqlcomm.ExecuteNonQuery();
- if (dt.Rows.Count > 0) {
- Session["user"] = UserNameTextBox;
- Response.Redirect("~/Default.aspx");
- }
- else {}
- if (!AuthHelper.SignIn(UserNameTextBox.Text, PasswordButtonEdit.Text)) {
- GeneralErrorDiv.InnerText = "Invalid login attempt.";
- FormLayout.FindItemOrGroupByName("GeneralError").Visible = true;
-
- }
- else Response.Redirect("~/Default.aspx");
- }
- }
- }
- }
and this my sign in code kindly advise me what's wrong I am not able to, getting the value from the session and then casting as ApplicationUser.