---
title: "Logon user contro change to as logoff when logged"  
description: "Logon user contro change to as logoff when logged"  
author: "venkat gosetty"  
published: 2011-11-02  
updated: 2011-11-02  
canonical: https://www.mindstick.com/forum/342/logon-user-contro-change-to-as-logoff-when-logged  
category: "asp.net mvc"  
tags: ["asp.net mvc"]  
reading_time: 2 minutes  

---

# Logon user contro change to as logoff when logged

Hi Thanks in [advance](https://www.mindstick.com/blog/33258/jee-mains-and-jee-advance-exams),\
\
Doubts on [logon and logoff](https://www.mindstick.com/forum/343/logon-and-logoff-user-controls-how-to-set-isauthenticated-is-true) user controls. I have taken [model class](https://www.mindstick.com/forum/160267/what-is-the-role-of-the-range-data-annotation-and-when-to-use-it-in-a-model-class) for logon functionality.How to write [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii) for when i am logged to next page. logon [user control](https://www.mindstick.com/forum/294/problem-in-access-the-control-inside-the-user-control) should change to logoff.

## Replies

### Reply by venkat gosetty

[Model](https://yourviews.mindstick.com/view/81334/america-is-reopening-after-corona-lockdown-but-on-swedish-model)\
\
[Required(ErrorMessage = "Email Id Required")]\
[DisplayName("Email ID")]\
[RegularExpression(@"^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$", ErrorMessage = "Email Format is wrong")]\
[StringLength(50, ErrorMessage = "Less than 50 characters")]\
\
public string EmailId { get; set; }\
\
[DataType(DataType.Password)]\
[Required(ErrorMessage = "Password Required")]\
[DisplayName("Password")]\
[StringLength(30, ErrorMessage = ":Less than 30 characters")]\
\
public string Password { get; set; }\
\
public int RoleId { get; set; }\
\
public string FirstName { get; set; }\
\
public bool IsUserExist(string emailid, string password)\
{\
bool flag= false;\
con.Open();\
SqlDataReader dr;\
SqlCommand cmd = new SqlCommand("select count(*) from Security.Users where UserName='" + emailid + "' and Password='" + password + "'", con);\
SqlCommand cmd1 = new SqlCommand("select RoleId from security.Users where UserName='" + emailid + "'", con);\
flag= Convert.ToBoolean(cmd.ExecuteScalar());\
dr = cmd1.ExecuteReader();\
if (dr.Read() == true)\
{\
RoleId = Convert.ToInt32(dr[0].ToString());\
}\
dr.Close();\
con.Close();\
return flag;\
}\
\
Controller\
\
[HttpPost, ValidateInput(false)]\
public ActionResult LogOn(Login model)\
{\
if (ModelState.IsValid)\
{\
if (model.IsUserExist(model.EmailId, model.Password))\
{\
model.FirstName = [User](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server).Identity.Name;\
if (model.RoleId == 1)\
{\
model.IsLoggedIn();\
return RedirectToAction("Index", "SuperAdmin");\
}\
else if (model.RoleId == 2)\
{\
model.IsLoggedIn();\
return RedirectToAction("Home", "Admin");\
}\
else if (model.RoleId == 3)\
{\
model.IsLoggedIn();\
return RedirectToAction("Index", "AppHome");\
}\
}\
else\
{\
ModelState.AddModelError("", "EmailId or Password do not match");\
}\
}\
ViewData["RoleId"] = model.RoleId;\
ViewData["FirstName"] = model.FirstName;\
return View(model);\
}

### Reply by Chris Anderson

Hi,\
\
Refer this link.\
\
[https://www.mindstick.com/forum/340/update-the-login-control](https://www.mindstick.com/forum/340/update-the-login-control)\
\
I think this will help you.

### Reply by John Smith

Paste your code here...


---

Original Source: https://www.mindstick.com/forum/342/logon-user-contro-change-to-as-logoff-when-logged

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
