dinesh.k
dinesh.k

Reputation: 197

set controllers using custom role provider in mvc 4

I am new to custom role providers and roles. I need to show some functionalities in the home page.

I can do this using JavaScript but I need to implement this by using custom role provider. Is it possible using MVC4?

I have searched lots of websites but I did not find out how to do it. Can anyone give me some examples for this.

Upvotes: 0

Views: 219

Answers (1)

Rob
Rob

Reputation: 11798

You can include admin areas in your view with razor like that:

@{if (User.IsInRole("admin"))
    {
        <text>
        @Html.ActionLink("Administration", "Index", "Admin", null, new { @class = currentPage == "admin-index" ? "currentPage" : "" });
        </text>
    }
}

In your controller you should make sure that admin settings and command that get sent (via Ajax post, e.g.) in come frome an authenticated admin user. Just an example:

    [HttpPost]
    [AccessDeniedAuthorize(Roles = "admin")]
    public JsonResult SaveOrder(int StationId, string ca, string items)
    {
         ...[your code]...
    }

Upvotes: 1

Related Questions