BstHelpers.Web 10.0.10

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
BstErrorService
Error Service
15
BstErrorService
Error Service
16
BstErrorService
Error Service
17
BstErrorService
Error Service
19
BstErrorService
Error Service
22
BstErrorService
Error Service
23
BstErrorService
Error Service
24
BstErrorService
Error Service
26
BstErrorService
Error Service
29
BstErrorService
Error Service
30
BstErrorService
Error Service
44

Version Downloads Last updated
10.0.10 3 03/05/2026
10.0.9 9 23/04/2026
10.0.8 8 16/04/2026
10.0.7 5 13/04/2026
10.0.6 27 20/03/2026
10.0.5 17 11/03/2026
10.0.4 16 10/02/2026
10.0.3 12 28/01/2026
10.0.2 23 12/12/2025
10.0.1 17 11/11/2025
9.1.5 16 20/10/2025
9.1.4 8 20/10/2025
9.1.2 10 15/10/2025
9.1.1 9 24/09/2025
9.1.0 26 06/09/2025
9.0.9 24 15/07/2025
9.0.8 18 12/06/2025
9.0.7 50 14/05/2025
9.0.6 28 22/04/2025
9.0.5 20 09/04/2025
9.0.4 31 19/03/2025
9.0.3 20 08/03/2025
9.0.2 24 07/03/2025
9.0.1 17 01/03/2025