Check user authorization in Orchard CMS

I am writing a module for Orchard CMS, and I need to show all parts of my content type only if the user is authorized. Can I do this in my module view (.cshtml)?

Something about this:

if(<statement_about_authorization>) @T("part_1"): @Model.part_1<br /> else @T("part_2"): @Model.part_2<br /> 

Or maybe with javascript?

+4
source share
2 answers

I never confused with Orchard, but in MVC with asp.net forms authentication it would look like this:

 if(User.Identity.IsAuthenticated) @T("part_1"): @Model.part_1<br /> else @T("part_2"): @Model.part_2<br /> 

From a small number of search queries, this seems to work for Orchard as well.

+3
source

Regular User.Identity.IsAuthenticated will work, but Orchard has a good way to authorize your users based on specific permissions too ...

 @if(Authorizer.Authorize(Permissions.PermissionName){ } 

You can learn more about defining permissions here: Garden Permissions

And an example blogs module on how to define your own permissions: An example of permissions for blogs

+9
source

All Articles