Skip to content

Instantly share code, notes, and snippets.

@AThraen
Created May 26, 2020 12:49
Show Gist options
  • Select an option

  • Save AThraen/4c36fe42554444150d39f78283b34e6c to your computer and use it in GitHub Desktop.

Select an option

Save AThraen/4c36fe42554444150d39f78283b34e6c to your computer and use it in GitHub Desktop.
Use a virtual role to only show blocks available for the current site
public class SiteVirtualRole : VirtualRoleProviderBase
{
public string Site { get; set; }
public override void Initialize(string name, NameValueCollection config)
{
base.Initialize(name, config);
Site = config["site"];
}
public override bool IsInVirtualRole(IPrincipal principal, object context)
{
var site = HttpContext.Current?.Request?.Url?.Host;
if (!string.IsNullOrEmpty(site) && (site.ToLower() == Site.ToLower())) return true;
return false;
}
}
@AdamTaylorQuilter

Copy link
Copy Markdown

This is great but context is always null for me. Did you experience that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment