You must Sign In to post a response.
  • Category: ASP.NET

    Custom Form Authentication in MVC 4.0

    I want to use form authentication on my site in order to login I already have my database schema, I don't want to use the ASP.NET membership tables for SQL Server. Previously i was using session which is given below


    #region [GLOBAL DECLARATION]
    static UserSession _nonWebSession;
    protected int _userPkey;
    #endregion

    #region [PROPERTY DECLARTION]

    public int UserID { get; set; }

    public bool IsLoggedIn
    {
    get { return UserID != 0 ? true : false; }
    }

    public bool IsDoctorLogin { get; set; }

    public string UserFullName { get; set; }

    public string EmailAddress { get; set; }

    public int SpecialityID { get; set; }

    public int UserTypeFK { get; set; }

    public string UserName { get; set; }


    #endregion

    #region [CONSTRUCTOR]
    public UserSession()
    {
    Init();
    }
    #endregion

    #region [PUBLIC METHOD]

    public static UserSession Inst
    {
    get
    {

    if (System.Web.HttpContext.Current == null)
    {
    if (_nonWebSession == null) _nonWebSession = new UserSession();
    return _nonWebSession;
    }
    else
    {
    if (HttpContext.Current.Handler is IRequiresSessionState || HttpContext.Current.Handler is IReadOnlySessionState)
    {
    return (UserSession)HttpContext.Current.Session["AuthorizedUser"];
    }
    else
    {
    return new UserSession();
    }
    }
    }

    }

    public static void Create()
    {
    UserSession userSess = (UserSession)HttpContext.Current.Session["AuthorizedUser"];
    if (userSess == null)
    HttpContext.Current.Session["AuthorizedUser"] = new UserSession();
    }

    private void Init()
    {
    try
    {
    if (HttpContext.Current == null) HttpContext.Current.Session["AuthorizedUser"] = new UserSession();
    string httpHost = HttpContext.Current.Request.ServerVariables["HTTP_HOST"].ToLower();
    }
    catch { }
    }

    public void Logout()
    {
    Init();
    UserID = 0;
    UserTypeFK = 0;
    SpecialityID = 0;
    IsDoctorLogin = false;
    UserName = string.Empty;
    EmailAddress = string.Empty;
    UserFullName = string.Empty;
    HttpContext.Current.Session.Abandon();
    }

    public void Login(int iUserPkey, int iUserTypeFk, int iSpecialityID, string sUserFullName, string sUserName, string sEmailAddress, bool bIsDoctorLogin)
    {
    UserID = iUserPkey;
    UserTypeFK = iUserTypeFk;
    SpecialityID = iSpecialityID;
    UserFullName = sUserFullName;
    EmailAddress = sEmailAddress;
    UserName = sUserName;
    IsDoctorLogin = bIsDoctorLogin;

    }

    Now i want to use form authentication where i want to access given above properties after login.
  • #764658
    I Guess below article may help you. Please go through it let me know if it helps,

    https://msdn.microsoft.com/en-us/library/ff398049(v=vs.100).aspx

    http://www.dotnetawesome.com/2015/06/how-to-implement-custom-forms-authentication-in-aspnet-mvc.html


    Regards,
    Asheej T K
    Microsoft MVP[ASP.NET/IIS]
    DotNetSpider MVM


Sign In to post your comments