Created
May 26, 2020 12:49
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is great but context is always null for me. Did you experience that?