#6 CmsContext.User – ID, Permissions, etc.
Requirements
Resources
Interface ICmsUser
Get information about the user which is currently used by the code.
On the new RazorPro
it's on MyUser
or on MyContext.User
.
On the older Razor14
or Razor12
it's on CmsContext.User
.
Output
-
.Id
of the current user: -1 -
.IsSiteAdmin
False (check if the current user is a site admin) -
.IsContentAdmin
False (check if the current user can edit content) -
.IsSystemAdmin
False (check if the current user is a supe-user)
#6 CmsContext.User – ID, Permissions, etc.
Source Code of this file
Below you'll see the source code of the file. Note that we're just showing the main part, and hiding some parts of the file which are not relevant for understanding the essentials. Click to expand the code
@inherits Custom.Hybrid.RazorTyped @using ToSic.Razor.Blade; <!-- unimportant stuff, hidden --> <div @Sys.PageParts.InfoWrapper()> @Html.Partial("../shared/DefaultInfoSection.cshtml") <div @Sys.PageParts.InfoIntro()> <h2>Interface ICmsUser</h2> <p> Get information about the user which is currently used by the code. </p> <p>On the new <code>RazorPro</code> it's on <code>MyUser</code> or on <code>MyContext.User</code>.</p> <p>On the older <code>Razor14</code> or <code>Razor12</code> it's on <code>CmsContext.User</code>.</p> </div> </div> <ol> <li> <code>.Id</code> of the current user: <strong>@MyUser.Id</strong> </li> <li> <code>.IsSiteAdmin</code> <strong>@MyUser.IsSiteAdmin</strong> (check if the current user is a site admin) </li> <li> <code>.IsContentAdmin</code> <strong>@MyUser.IsSiteAdmin</strong> (check if the current user can edit content) </li> <li> <code>.IsSystemAdmin</code> <strong>@MyUser.IsSystemAdmin</strong> (check if the current user is a supe-user) </li> </ol> @* Snippet for the old v14 code, which shouldn't run but should be shown. This is a bit of a hack, but it works <ol> <li> <code>.Id</code> of the current user: <strong>@CmsContext.User.Id</strong> </li> <li> <code>.IsSiteAdmin</code> <strong>@CmsContext.User.IsSiteAdmin</strong> (check if the current user is a site admin) </li> <li> <code>.IsContentAdmin</code> <strong>@CmsContext.User.IsSiteAdmin</strong> (check if the current user can edit content) </li> <li> <code>.IsSystemAdmin</code> <strong>@CmsContext.User.IsSystemAdmin</strong> (check if the current user is a supe-user) </li> </ol> *@ @* Footer *@ @Html.Partial("../Shared/Layout/FooterWithSource.cshtml", new { Sys = Sys })