user1740381
user1740381

Reputation: 2199

_start.cshtml view is not executing

I am using Asp.Net MVC-4 in my application. I have created a controller, for eample say Person and in this controller i have 3 Actions for example say GetName, GetAge and GetDateOfBirth. Now what i want is to place a check so that the user who are not loggedin can't get access to these action view.

For this i am trying to use _start.cshtml view. Which i placed inside the Views/Person/ and i am expecting that whenever any user will access any view from inside Person folder than _start.cshtml view should run before any other view. And in *_start.cshtml* i placed a code to check for whether current user is logged in or not. But the _star.cshtml is not executing.

Can anyone please tell me what i am doing wrong ?

Upvotes: 1

Views: 248

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038850

Now what i want is to place a check so that the user who are not loggedin can't get access to these action view

That's absolutely not something that should be done in views but on the controller actions, by decorating them with the [Authorize] attribute. For example:

[Authorize]
public ActionResult SomeAction()
{
    ...
}

and you also have the possibility to specify one or more roles:

[Authorize(Roles = "Admin")]
public ActionResult SomeAction()
{
    ...
}

You could also decorate a controller with this attribute which would mean that all actions in it require authorization.

Upvotes: 5

Related Questions