---
title: "Hi Rohith, I am new for mvc. Please explain how to set implicitly IsAuthenticated true."  
description: "Hi Rohith, I am new for mvc. Please explain how to set implicitly IsAuthenticated true."  
author: "venkat gosetty"  
published: 2011-11-02  
updated: 2011-11-18  
canonical: https://www.mindstick.com/forum/344/hi-rohith-i-am-new-for-mvc-please-explain-how-to-set-implicitly-isauthenticated-true  
category: "asp.net mvc"  
tags: ["asp.net mvc"]  
reading_time: 4 minutes  

---

# Hi Rohith, I am new for mvc. Please explain how to set implicitly IsAuthenticated true.

[Hi Rohith](https://www.mindstick.com/forum/348/hi-rohith-i-post-the-code-please-check-it-thank-you),\
\
[Please explain](https://www.mindstick.com/forum/159385/how-does-http-file-upload-work-please-explain) how to set implicitly IsAuthenticated true. If you have [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii) please [post](https://www.mindstick.com/articles/12829/aspects-that-make-australia-post-shipping-extension-a-useful-tool) me.\
\
Thank you\
\

## Replies

### Reply by venkat gosetty

hi,\
how to validate validations whether textbox is empty or not. using linq to sql.

### Reply by venkat gosetty

it's not working

### Reply by Chris Anderson

Have you checked Request.IsAuthenticated returns true or false. If it returns true then it will only display user name.\
\
Write the below code without if condition and then check whether it displays or not:\
\
Welcome <b><%: ViewData["Name"] %></b>!

### Reply by venkat gosetty

I have written code for Request.IsAutheticated \
\

```
[HttpPost, ValidateInput(false)]        public ActionResult LogOn(Login model)        {            if (ModelState.IsValid)            {                if (model.IsUserExist(model.EmailId, model.Password))                {                    FormsAuthentication.SetAuthCookie(model.EmailId, true);                    if (model.RoleId == 1)                    {                        model.IsLoggedIn();                        ViewData["Name"] = model.FirstName;                        return RedirectToAction("Dashboard", "SuperAdmin");                    }                    else if (model.RoleId == 2)                    {                        model.IsLoggedIn();                        return RedirectToAction("Dashboard", "Admin");                    }                    else if (model.RoleId == 3)                    {                        model.IsLoggedIn();                        return RedirectToAction("Dashboard", "AppHome");                    }                }                else                {                    ModelState.AddModelError("", "EmailId or Password do not match");                }            }            return View(model);        }
```

\
**and my .ascx**\
\

```
if (Request.IsAuthenticated) {%>        Welcome <b><%: ViewData["Name"] %></b>!        <%: Html.ActionLink("Log Off", "LogOff", "Account") %>       <%    }
```

\
not display the username and also no error

### Reply by Chris Anderson

First store user name:\
\
ViewBag.UserName="assign user name";\
\
then display it:\
\

```
if (Request.IsAuthenticated) {%>        Welcome <b><%: ViewBag.UserName %></b>!        <%: Html.ActionLink("Log Off", "LogOff", "Account") %>       <%}
```

\
how you set set Request.IsAuthenticated to true when you are using database as a medium to store data?

### Reply by venkat gosetty

Hi Rohith,

I want display in master page. \
\

```
 if (Request.IsAuthenticated) {%>        Welcome <b><%: Page.User.Identity.Name %></b>!        <%: Html.ActionLink("Log Off", "LogOff", "Account") %>       <%    }
```

### Reply by Chris Anderson

So, store the first name when user logged in, either create a property or a ViewData property wherever you want to store and display it.

### Reply by venkat gosetty

yes Rohith i got that. But i am getting welcome To as Username when i logged. I want display FirstName Field after logged.

### Reply by Chris Anderson

So, finally you got your answer?

### Reply by venkat gosetty

I am using sqlserver database\
\
**Model**\
\

```
public class Login    {        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["EMM360ConnectionString"].ConnectionString);        [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**\
\
Recently i added the FormsAuthentication.SetAuthCookie(model.EmailId, true); Now it is working fine.\
\

```
[HttpPost, ValidateInput(false)]        public ActionResult LogOn(Login model)        {            if (ModelState.IsValid)            {                if (model.IsUserExist(model.EmailId, model.Password))                {                    FormsAuthentication.SetAuthCookie(model.EmailId, true);                    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");                }            }            return View(model);        }
```

### Reply by Chris Anderson

Hi,\
\
Could you [explain](https://www.mindstick.com/forum/157854/what-is-system-debugging-explain-some-system-debugging-tools-used-in-modern-computer-systems) me where you have store the user information either in Membership or database.\
If you are using Membership to store user information, you can refer demo application provided by mvc in visual studio.\
If you are using database, you can build your own logic to authenticate user.\
If not able to understand paste your code here...\
\
Thanks.


---

Original Source: https://www.mindstick.com/forum/344/hi-rohith-i-am-new-for-mvc-please-explain-how-to-set-implicitly-isauthenticated-true

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
