{"id":30420739,"url":"https://github.com/skybrud/skybrud.essentials.aspnetcore","last_synced_at":"2026-02-23T18:06:24.924Z","repository":{"id":41988251,"uuid":"437961238","full_name":"skybrud/Skybrud.Essentials.AspNetCore","owner":"skybrud","description":"Skybrud.Essentials addon for working with ASP.NET Core.","archived":false,"fork":false,"pushed_at":"2025-04-24T21:27:01.000Z","size":626,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"v1/main","last_synced_at":"2025-08-22T08:26:39.477Z","etag":null,"topics":["asp-net","asp-net-core","limbo","net5","nuget","package","skybrud","skybrud-essentials"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/skybrud.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2021-12-13T17:19:20.000Z","updated_at":"2025-04-24T21:27:05.000Z","dependencies_parsed_at":"2025-04-24T22:32:19.369Z","dependency_job_id":"3888a313-8845-4c1b-92f8-aa31be674924","html_url":"https://github.com/skybrud/Skybrud.Essentials.AspNetCore","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"purl":"pkg:github/skybrud/Skybrud.Essentials.AspNetCore","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skybrud%2FSkybrud.Essentials.AspNetCore","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skybrud%2FSkybrud.Essentials.AspNetCore/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skybrud%2FSkybrud.Essentials.AspNetCore/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skybrud%2FSkybrud.Essentials.AspNetCore/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/skybrud","download_url":"https://codeload.github.com/skybrud/Skybrud.Essentials.AspNetCore/tar.gz/refs/heads/v1/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skybrud%2FSkybrud.Essentials.AspNetCore/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29749952,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-23T07:44:07.782Z","status":"ssl_error","status_checked_at":"2026-02-23T07:44:07.432Z","response_time":90,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["asp-net","asp-net-core","limbo","net5","nuget","package","skybrud","skybrud-essentials"],"created_at":"2025-08-22T08:20:02.682Z","updated_at":"2026-02-23T18:06:24.910Z","avatar_url":"https://github.com/skybrud.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Skybrud.Essentials.AspNetCore\n\n[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE.md)\n[![NuGet](https://img.shields.io/nuget/vpre/Skybrud.Essentials.AspNetCore.svg)](https://www.nuget.org/packages/Skybrud.Essentials.AspNetCore)\n[![NuGet](https://img.shields.io/nuget/dt/Skybrud.Essentials.AspNetCore.svg)](https://www.nuget.org/packages/Skybrud.Essentials.AspNetCore)\n[![Skybrud.Essentials.AspNetCore at packages.limbo.works](https://img.shields.io/badge/limbo-packages-blue)](https://packages.limbo.works/skybrud.essentials.aspnetcore/)\n\n**Skybrud.Essentials.AspNetCore** is an add-on that builds on top of our [Skybrud.Essentials](https://github.com/skybrud/Skybrud.Essentials) package, and it provides various logic that makes it easier to work with different parts of ASP.NET Core - eg. parsing query strings and reading request headers..\n\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003cstrong\u003eLicense:\u003c/strong\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"./LICENSE.md\"\u003e\u003cstrong\u003eMIT License\u003c/strong\u003e\u003c/a\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003cstrong\u003eTarget Frameworks:\u003c/strong\u003e\u003c/td\u003e\n    \u003ctd\u003e.NET 5, .NET 6 and .NET 7\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n\u003cbr /\u003e\u003cbr /\u003e\n\n## Installation\n\n### NuGet\n\nTo install the package via [**NuGet**](https://www.nuget.org/packages/Skybrud.Essentials.AspNetCore), you can use either .NET CLI:\n\n```\ndotnet add package Skybrud.Essentials.AspNetCore\n```\n\nor the NuGet package manager:\n\n```\nInstall-Package Skybrud.Essentials.AspNetCore\n```\n\n\u003cbr /\u003e\u003cbr /\u003e\n\n## Examples\n\n### Extension methods for `HttpRequest`\n\n```cshtml\n@using Microsoft.AspNetCore.Http\n@using Skybrud.Essentials.AspNetCore\n\n@inject IHttpContextAccessor HttpContextAccessor\n\n@{\n\n    HttpRequest request = HttpContextAccessor.HttpContext.Request;\n\n    Uri uri = request.GetUri();\n    \n    \u003cpre\u003eScheme: @uri.Scheme\u003c/pre\u003e\n    \u003cpre\u003eHost: @uri.Host\u003c/pre\u003e\n    \u003cpre\u003ePort: @uri.Port\u003c/pre\u003e\n    \u003cpre\u003ePathAndQuery: @uri.PathAndQuery\u003c/pre\u003e\n    \u003cpre\u003eToString: @uri.ToString()\u003c/pre\u003e\n    \u003cpre\u003eAuthority: @uri.GetLeftPart(UriPartial.Authority)\u003c/pre\u003e\n    \u003cpre\u003ePathAndQuery: @uri.PathAndQuery\u003c/pre\u003e\n\n    \u003chr /\u003e\n\n    \u003cpre\u003eRemote Address: @request.GetRemoteAddress()\u003c/pre\u003e\n    \u003cpre\u003eAccept Types: @request.GetAcceptTypes()\u003c/pre\u003e\n    \u003cpre\u003eAccept Encoding: @request.GetAcceptEncoding()\u003c/pre\u003e\n    \u003cpre\u003eAccept Languages: @request.GetAcceptLanguage()\u003c/pre\u003e\n    \u003cpre\u003eUser Agent: @request.GetUserAgent()\u003c/pre\u003e\n    \u003cpre\u003eReferrer: @request.GetReferrer()\u003c/pre\u003e\n\n}\n```\n\n\u003cbr /\u003e\u003cbr /\u003e\n\n### Extension methods for `IQueryCollection`\n\n#### Strings\n\n```cshtml\n@using Microsoft.AspNetCore.Http\n@using Microsoft.Extensions.Primitives\n@using Skybrud.Essentials.AspNetCore\n@{\n\n    IQueryCollection query = new QueryCollection(new Dictionary\u003cstring, StringValues\u003e {\n        {\"id\", new StringValues(\"1\")},\n        {\"ids\", new StringValues(new []{\"1\", \"2\", \"3\"})},\n        {\"moreIds\", new StringValues(new []{\"5,6\", \"7\", \"8\"})}\n    });\n\n    // Prints \"1\"\n    string? id = query.GetString(\"id\");\n    \u003cpre\u003e@id\u003c/pre\u003e\n\n    // Prints \"1,2,3\"\n    string[] ids = query.GetStringArray(\"ids\");\n    \u003cpre\u003e@string.Join(\",\", ids)\u003c/pre\u003e\n\n    // Prints \"5,6,7,8\"\n    List\u003cstring\u003e moreIds = query.GetStringList(\"moreIds\");\n    \u003cpre\u003e@string.Join(\",\", moreIds)\u003c/pre\u003e\n\n    // Prints \"'nope' not found\"\n    if (query.TryGetString(\"nope\", out string? nope)) {\n        \u003cpre\u003e@nope\u003c/pre\u003e\n    } else {\n        \u003cpre\u003e'nope' not found.\u003c/pre\u003e\n    }\n\n}\n```\n\n#### Int32\n\n```cshtml\n@using Microsoft.AspNetCore.Http\n@using Microsoft.Extensions.Primitives\n@using Skybrud.Essentials.AspNetCore\n@{\n\n    IQueryCollection query = new QueryCollection(new Dictionary\u003cstring, StringValues\u003e {\n        {\"id\", new StringValues(\"1\")},\n        {\"ids\", new StringValues(new []{\"1\", \"2\", \"3\"})},\n        {\"moreIds\", new StringValues(new []{\"5,6\", \"7\", \"8\"})}\n    });\n\n    // Prints \"1\"\n    int id = query.GetInt32(\"id\");\n    \u003cpre\u003e@id\u003c/pre\u003e\n\n    // Prints \"2\" (via fallback)\n    int id2 = query.GetInt32(\"id2\", 2);\n    \u003cpre\u003e@id2\u003c/pre\u003e\n\n    // Prints \"\" (since null is rendered as empty)\n    int? id3 = query.GetInt32OrNull(\"id3\");\n    \u003cpre\u003e@id3\u003c/pre\u003e\n\n    // Prints \"1,2,3\"\n    int[] ids = query.GetInt32Array(\"ids\");\n    \u003cpre\u003e@string.Join(\",\", ids)\u003c/pre\u003e\n\n    // Prints \"5,6,7,8\"\n    List\u003cint\u003e moreIds = query.GetInt32List(\"moreIds\");\n    \u003cpre\u003e@string.Join(\",\", moreIds)\u003c/pre\u003e\n\n    // Prints \"'nope' not found\"\n    if (query.TryGetInt32(\"nope\", out int? nope)) {\n        \u003cpre\u003e@nope\u003c/pre\u003e\n    } else {\n        \u003cpre\u003e'nope' not found.\u003c/pre\u003e\n    }\n\n}\n```\n\n#### Int64\n\n```cshtml\n@using Microsoft.AspNetCore.Http\n@using Microsoft.Extensions.Primitives\n@using Skybrud.Essentials.AspNetCore\n@{\n\n    IQueryCollection query = new QueryCollection(new Dictionary\u003cstring, StringValues\u003e {\n        {\"id\", new StringValues(\"1\")},\n        {\"ids\", new StringValues(new []{\"1\", \"2\", \"3\"})},\n        {\"moreIds\", new StringValues(new []{\"5,6\", \"7\", \"8\"})}\n    });\n\n    // Prints \"1\"\n    long id = query.GetInt64(\"id\");\n    \u003cpre\u003e@id\u003c/pre\u003e\n\n    // Prints \"2\" (via fallback)\n    long id2 = query.GetInt64(\"id2\", 2);\n    \u003cpre\u003e@id2\u003c/pre\u003e\n\n    // Prints \"\" (since null is rendered as empty)\n    long? id3 = query.GetInt64OrNull(\"id3\");\n    \u003cpre\u003e@id3\u003c/pre\u003e\n\n    // Prints \"1,2,3\"\n    long[] ids = query.GetInt64Array(\"ids\");\n    \u003cpre\u003e@string.Join(\",\", ids)\u003c/pre\u003e\n\n    // Prints \"5,6,7,8\"\n    List\u003clong\u003e moreIds = query.GetInt64List(\"moreIds\");\n    \u003cpre\u003e@string.Join(\",\", moreIds)\u003c/pre\u003e\n\n    // Prints \"'nope' not found\"\n    if (query.TryGetInt64(\"nope\", out long? nope)) {\n        \u003cpre\u003e@nope\u003c/pre\u003e\n    } else {\n        \u003cpre\u003e'nope' not found.\u003c/pre\u003e\n    }\n\n}\n```\n\n#### Float\n\n```cshtml\n@using Microsoft.AspNetCore.Http\n@using Microsoft.Extensions.Primitives\n@using Skybrud.Essentials.AspNetCore\n@{\n\n    IQueryCollection query = new QueryCollection(new Dictionary\u003cstring, StringValues\u003e {\n        {\"pi\", new StringValues(\"3.14\")},\n        {\"values\", new StringValues(new []{\"3.14\", \"6.28\", \"9.42\"})},\n        {\"otherValues\", new StringValues(new []{\"3.14,6.28\", \"9.42\"})}\n    });\n\n    // Prints \"3.14\"\n    float pi = query.GetFloat(\"pi\");\n    \u003cpre\u003e@pi\u003c/pre\u003e\n\n    // Prints \"1.23\" (via fallback)\n    float meh = query.GetFloat(\"meh\", 1.23f);\n    \u003cpre\u003e@meh\u003c/pre\u003e\n\n    // Prints \"\" (since null is rendered as empty)\n    float? meh2 = query.GetFloatOrNull(\"meh\");\n    \u003cpre\u003e@meh2\u003c/pre\u003e\n\n    // Prints \"3.14,6.28,9.42\"\n    float[] values = query.GetFloatArray(\"values\");\n    \u003cpre\u003e@string.Join(\",\", values)\u003c/pre\u003e\n\n    // Prints \"3.14,6.28,9.42\"\n    List\u003cfloat\u003e otherValues = query.GetFloatList(\"otherValues\");\n    \u003cpre\u003e@string.Join(\",\", otherValues)\u003c/pre\u003e\n\n    // Prints \"'nope' not found\"\n    if (query.TryGetFloat(\"nope\", out float? nope)) {\n        \u003cpre\u003e@nope\u003c/pre\u003e\n    } else {\n        \u003cpre\u003e'nope' not found.\u003c/pre\u003e\n    }\n\n}\n```\n\n#### Double\n\n```cshtml\n@using Microsoft.AspNetCore.Http\n@using Microsoft.Extensions.Primitives\n@using Skybrud.Essentials.AspNetCore\n@{\n\n    IQueryCollection query = new QueryCollection(new Dictionary\u003cstring, StringValues\u003e {\n        {\"pi\", new StringValues(\"3.1415926535\")},\n        {\"values\", new StringValues(new []{\"3.1415926535\", \"6.283185307\", \"9.4247779605\"})},\n        {\"otherValues\", new StringValues(new []{\"3.1415926535,6.283185307\", \"9.4247779605\"})}\n    });\n\n    // Prints \"3.1415926535\"\n    double pi = query.GetDouble(\"pi\");\n    \u003cpre\u003e@pi\u003c/pre\u003e\n\n    // Prints \"1.23\" (via fallback)\n    double meh = query.GetDouble(\"meh\", 1.23);\n    \u003cpre\u003e@meh\u003c/pre\u003e\n\n    // Prints \"\" (since null is rendered as empty)\n    double? meh2 = query.GetDoubleOrNull(\"meh\");\n    \u003cpre\u003e@meh2\u003c/pre\u003e\n\n    // Prints \"3.1415926535,6.283185307,9.4247779605\"\n    double[] values = query.GetDoubleArray(\"values\");\n    \u003cpre\u003e@string.Join(\",\", values)\u003c/pre\u003e\n\n    // Prints \"3.1415926535,6.283185307,9.4247779605\"\n    List\u003cdouble\u003e otherValues = query.GetDoubleList(\"otherValues\");\n    \u003cpre\u003e@string.Join(\",\", otherValues)\u003c/pre\u003e\n\n    // Prints \"'nope' not found\"\n    if (query.TryGetDouble(\"nope\", out double? nope)) {\n        \u003cpre\u003e@nope\u003c/pre\u003e\n    } else {\n        \u003cpre\u003e'nope' not found.\u003c/pre\u003e\n    }\n\n}\n```\n\n#### Boolean\n\n```cshtml\n@using Microsoft.AspNetCore.Http\n@using Microsoft.Extensions.Primitives\n@using Skybrud.Essentials.AspNetCore\n@{\n\n    IQueryCollection query = new QueryCollection(new Dictionary\u003cstring, StringValues\u003e {\n        {\"a\", new StringValues(\"true\")},\n        {\"b\", new StringValues(\"1\")}\n    });\n\n    // Prints \"True\"\n    bool a = query.GetBoolean(\"a\");\n    \u003cpre\u003e@a\u003c/pre\u003e\n\n    // Prints \"True\"\n    bool b = query.GetBoolean(\"b\");\n    \u003cpre\u003e@b\u003c/pre\u003e\n\n    // Prints \"False\"\n    bool c = query.GetBoolean(\"c\");\n    \u003cpre\u003e@c\u003c/pre\u003e\n\n    // Prints \"True\" (via fallback)\n    bool d = query.GetBoolean(\"d\", true);\n    \u003cpre\u003e@d\u003c/pre\u003e\n\n    // Prints \"\" (since null is rendered as empty)\n    bool? e = query.GetBooleanOrNull(\"e\");\n    \u003cpre\u003e@e\u003c/pre\u003e\n\n    // Prints \"'nope' not found\"\n    if (query.TryGetBoolean(\"nope\", out bool? nope)) {\n        \u003cpre\u003e@nope\u003c/pre\u003e\n    } else {\n        \u003cpre\u003e'nope' not found.\u003c/pre\u003e\n    }\n\n}\n```\n\n\u003cbr /\u003e\u003cbr /\u003e\n\n### Forcing API controllers to use Newtonsoft.Json\n\nBy default, ASP.NET Core uses the logic within the `System.Text.Json` namespace to serialize models to JSON. If you wish to use the `Newtonsoft.Json` package instead, there are a few different approaches for doing so:\n\n#### Use the `Microsoft.AspNetCore.Mvc.NewtonsoftJson` package\n\nThis package let's you set up all your API controllers to use `Newtonsoft.Json` for serializing JSON. This is a global setting, so be aware that this may affect parts of your application that it shouldn't.\n\nYou don't need `Skybrud.Essentials.AspNetCore` when using this approach.\n\n\n#### Use the `NewtonsoftJsonResult` class\n\nAs an alternative to enabling the use of `Newtonsoft.Json` globally, you can use the `NewtonsoftJsonResult` class from this package. This let's you determine the output an method level - eg. have a controller where some methods use the default `System.Text.Json`, but where others use `Newtonsoft.Json`.\n\nThis `NewtonsoftJsonResult` extends ASP.NET Core's `ContentResult` class, and serves as a wrapper for your response body. You may use the `NewtonsoftJsonResult` constructor directly, which then let's you specify a HTTP status code and a value representing your response body. But the class also features a number of static methods for creating a new response with a specific status code:\n \n```csharp\npublic ActionResult Hello() {\n    return NewtonsoftJsonResult.Ok(new { yay = true } );\n}\n```\n\n```csharp\npublic ActionResult OhNoes() {\n  return NewtonsoftJsonResult.InternalError(\"The server made a boo boo.\");\n}\n```\n\nThe `NewtonsoftJsonResult.Ok` and `NewtonsoftJsonResult.Created` methods are used for creating successful responses, so they both take a single parameter representing the response body.\n\nOn the other hand, the `NewtonsoftJsonResult.BadRequest`, `NewtonsoftJsonResult.Unauthorized`, `NewtonsoftJsonResult.Forbidden`, `NewtonsoftJsonResult.NotFound` and `NewtonsoftJsonResult.InternalError` represent responsens wrapping an error, so they take a single string parameter with an error message.\n\nFor instance, the `NewtonsoftJsonResult.InternalError(\"The server made a boo boo.\")` from before will result in a response with a 500 status code and the following JSON body:\n\n```json\n{\n  \"meta\": {\n    \"code\": 500,\n    \"error\": \"The server made a boo boo.\"\n  }\n}\n```\n\n#### Use `NewtonsoftJsonOnlyConfigurationAttribute` on the controller\n\nIf you wish to set this up at the controller level, you can add the `NewtonsoftJsonOnlyConfigurationAttribute` to your API controller:\n\n```csharp\n[NewtonsoftJsonOnlyConfiguration]\npublic class MyController : Controller {\n\n    public ActionResult Hello() {\n        return new { yay = true };\n    }\n\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskybrud%2Fskybrud.essentials.aspnetcore","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fskybrud%2Fskybrud.essentials.aspnetcore","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskybrud%2Fskybrud.essentials.aspnetcore/lists"}