Author Top Nguyen
- .Net Core Utilities methods for Web:
- SiteMap Generation
- API meta paged collection: generate next, previous, first, last URL for paged collection with items, total and additional data.
- Best practice constants.
- Core of all Elect Web modules, standalize ecosystem.
- Package Manager
PM> Install-Package Elect.Web
- .NET CLI
dotnet add package Elect.Web
- SiteMap
- Set
SiteMapItem
attribute forAction
inController
to mask the Action is Site Map Item.
public class HomeController : Controller { [SiteMapItem(SiteMapItemFrequency.Hourly, 0.9)] public IActionResult Index() { return View(); } [SiteMapItem(SiteMapItemFrequency.Weekly, 0.9)] public IActionResult About() { return View(); } }
- Add
SiteMapController
to generate Site Map Index and Site Map Index Detail.
public class SiteMapController : Controller { /// <summary> /// Get all site map index /// </summary> /// <returns></returns> [HttpGet] [Route("~/sitemap.xml")] public ContentResult Index() { var listSiteMapIndex = new List<SiteMapIndexItemModel> { new SiteMapIndexItemModel(Url.AbsoluteAction("Main", "SiteMap")) // Add more site map index if needed }.ToArray(); var contentResult = new SiteMapIndexGenerator().GenerateContentResult(listSiteMapIndex); return contentResult; } /// <summary> /// Get all site map item by attributes /// </summary> /// <returns></returns> [HttpGet] [Route("~/sitemap/main.xml")] public ContentResult Main() { return SiteMapHelper.GetSiteMapContentResult(Url); } }
- Set
- API meta paged collection
// 1. Service Layers // Queryable Data var query = users.AsQueryable(); // Paged Result var total = query.Count(); var data = query.OrderBy(x => x.Id).Skip(model.Skip).Take(model.Take).ToList(); var pagedResult = new PagedResponseModel<UserModel> { Total = total, Items = data, AdditionalData = new Dictionary<string, object> { {"Sum of Id", data.Select(x => x.Id).DefaultIfEmpty(0).Sum()} // More additional Data if need } }; // 2. In Controller // Generate Paged Meta var pagedMeta = Url.GetPagedMeta(model, pagedResult); return Ok(pagedMeta);
- HttpUtils
- StringUtils
- IUrlHelperUtils
Elect.Web is licensed under the MIT License.