Skip to content

Instantly share code, notes, and snippets.

@davidknipe
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidknipe/d9fdd37ff86b37794e46 to your computer and use it in GitHub Desktop.
Save davidknipe/d9fdd37ff86b37794e46 to your computer and use it in GitHub Desktop.
Claims helper block
@model ListAllClaimsModel
<div>
<h3>@Model.BlockTitle</h3>
<table class="table table-striped table-condensed">
@*<thead>
<tr>
<th>Claims</th>
</tr>
</thead>*@
<tbody>
@foreach (var claim in Model.AllClaims)
{
<tr>
<td>
@claim.Type <br />
<strong>
@if (claim.Value.Length > 80)
{
@claim.Value.Substring(0, 80)
}
else
{
@claim.Value
}
</strong>
</td>
</tr>
}
</tbody>
</table>
</div>
using EPiServer.DataAbstraction;
using System.ComponentModel.DataAnnotations;
namespace EPiServerFS.Models.Blocks
{
[SiteContentType(GUID = "9442B0A5-A683-4811-BD25-31BC0232F83E")]
public class ListAllClaimsBlock : SiteBlockData
{
[Display(Order = 1, Name = "List title", GroupName = SystemTabNames.Content)]
public virtual string BlockTitle { get; set; }
public override void SetDefaultValues(ContentType contentType)
{
base.SetDefaultValues(contentType);
this.BlockTitle = "List of all claims for user:";
}
}
}
using EPiServer.Web.Mvc;
using EPiServerFS.Models.Blocks;
using EPiServerFS.Models.ViewModels;
using System.Security.Claims;
using System.Web.Mvc;
namespace EPiServerFS.Controllers
{
public class ListAllClaimsBlockController : BlockController<ListAllClaimsBlock>
{
public override ActionResult Index(ListAllClaimsBlock currentBlock)
{
ListAllClaimsModel model = new ListAllClaimsModel();
model.BlockTitle = currentBlock.BlockTitle;
if (this.User != null && (this.User as ClaimsPrincipal) != null && (this.User as ClaimsPrincipal).Identity.IsAuthenticated)
{
model.AllClaims = (this.User as ClaimsPrincipal).Claims;
}
return PartialView(model);
}
}
}
using System.Collections.Generic;
using System.Security.Claims;
namespace EPiServerFS.Models.ViewModels
{
public class ListAllClaimsModel
{
public string BlockTitle;
public IEnumerable<Claim> AllClaims;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment