BstHelpers.Web 10.0.14

BstHelpers.Web

Web/MVC companion to BstHelpers: extensions for HttpContext, ClaimsPrincipal, ISession, SelectList, IHtmlContent/TagBuilder, ViewContext, plus a <custom-tag> tag helper.

Tag helper

Register the tag helper assembly in _ViewImports.cshtml:

@addTagHelper *, BstHelpers.Web

Renders any HTML element from a single tag, forwarding attributes:

<custom-tag asp-tag="div" class="card"></custom-tag>
<custom-tag asp-tag="@(isLink ? "a" : "span")" href="@Model.Url" class="btn">@Model.Label</custom-tag>

Empty/whitespace attributes are skipped. If asp-tag is null, nothing is rendered.

Usage

HttpContext

var baseUrl = HttpContext.GetRequestBaseUrl(); // "https://example.com"

ClaimsPrincipal (User)

User.GetUserId();          // ClaimTypes.NameIdentifier as string
User.GetUserIdInt();       // same, parsed to int (0 if missing)
User.GetName();            // ClaimTypes.GivenName
User.IsLogged();           // authenticated AND user id != 0
User.ClaimValue("custom"); // arbitrary claim type

Session (ISession)

JSON-serialized object storage (Newtonsoft, ReferenceLoopHandling.Ignore):

HttpContext.Session.SetObject("cart", cart);
var cart = HttpContext.Session.GetObject<Cart>("cart");

SelectList

// From IEnumerable
var list = items.NewSelectList(dataValueField: "Id", dataTextField: "Name", selectedValue: 5);

// From IQueryable<T> (materializes async)
var list = await dbContext.Categories
    .Select(c => new { c.Id, c.Name })
    .NewSelectList("Id", "Name");

// Add a placeholder as the first option
list = list.SetPlaceholder("-- choose --");
list = list.SetPlaceholder(new HtmlString("<em>none</em>"));

HTML / TagBuilder rendering

IHtmlContent content = ...;
string html = content.ToHtmlString();

var tag = new TagBuilder("a");
tag.Attributes["href"] = "/x";
tag.InnerHtml.Append("link");
string html = tag.GetHtml();

ViewContext (in Razor views)

@using BstHelpers.Web.Extensions

@{
    var action = ViewContext.GetAction();
    var controller = ViewContext.GetController();
}

Showing the top 20 packages that depend on BstHelpers.Web.

Packages Downloads
BstAutoLog.Web
Bomsite Auto log web extensions
38
BstAutoLog.Web
Bomsite Auto log web extensions
53
BstAutoLog.Web
Bomsite Auto log web extensions
113
BstErrorService
Error Service
40
BstErrorService
Error Service
41
BstErrorService
Error Service
42
BstErrorService
Error Service
43
BstErrorService
Error Service
48
BstErrorService
Error Service
49
BstErrorService
Error Service
52
BstErrorService
Error Service
59
BstErrorService
Error Service
63
BstErrorService
Error Service
119

Version Downloads Last updated
10.0.14 2 22/09/2026
10.0.13 58 18/07/2026
10.0.12 118 14/06/2026
10.0.11 43 17/05/2026
10.0.10 26 03/05/2026
10.0.9 37 23/04/2026
10.0.8 24 16/04/2026
10.0.7 27 13/04/2026
10.0.6 45 20/03/2026
10.0.5 41 11/03/2026
10.0.4 35 10/02/2026
10.0.3 30 28/01/2026
10.0.2 49 12/12/2025
10.0.1 43 11/11/2025
9.1.5 37 20/10/2025
9.1.4 26 20/10/2025
9.1.2 28 15/10/2025
9.1.1 27 24/09/2025
9.1.0 46 06/09/2025
9.0.9 40 15/07/2025
9.0.8 38 12/06/2025
9.0.7 70 14/05/2025
9.0.6 46 22/04/2025
9.0.5 40 09/04/2025
9.0.4 48 19/03/2025
9.0.3 37 08/03/2025
9.0.2 41 07/03/2025
9.0.1 35 01/03/2025