ASP.NET Core: [FromQuery] usage and URL format

The name of the method and return type are completely ignored when you define your route explicitly via attributes like that. IActionResult shouldn’t be there. The correct URL would be: https://localhost:xxxxx/api/v1/ShelfID/{shelfID}/BookCollection?ID=”123″&Name=”HarryPotter” Furthermore, query string binding only works out of the box for primitive types (string, int, etc). To bind a class to a query string … Read more

How to get content value in Xunit when result returned in IActionResult type

Depends on what you expect returned. From previous example you used an action like this. [HttpGet(“{id}”)] public IActionResult Get(string id) { var r = unitOfWork.Resources.Get(id); unitOfWork.Complete(); Models.Resource result = ConvertResourceFromCoreToApi(r); if (result == null) { return NotFound(); } else { return Ok(result); } } That method will either return a OkObjectResult or a NotFoundResult. If … Read more

Asp Net Core Web Push Notifications

The node library you mention has been ported to c#: web-push-csharp. Here’s a simplified usage example taken directly from their site: var pushEndpoint = @”https://fcm.googleapis.com/fcm/send/efz_TLX_rLU:APA91bE6U0iybLYvv0F3mf6uDLB6….”; var p256dh = @”BKK18ZjtENC4jdhAAg9OfJacySQiDVcXMamy3SKKy7FwJcI5E0DKO9v4V2Pb8NnAPN4EVdmhO…………”; var auth = @”fkJatBBEl……………”; var subject = @”mailto:example@example.com”; var publicKey = @”BDjASz8kkVBQJgWcD05uX3VxIs_gSHyuS023jnBoHBgUbg8zIJvTSQytR8MP4Z3-kzcGNVnM……………”; var privateKey = @”mryM-krWj_6IsIMGsd8wNFXGBxnx……………”; var subscription = new PushSubscription(pushEndpoint, p256dh, auth); var vapidDetails = … Read more

ASP.NET CORE, Web API: No route matches the supplied values

ASP.net core 3 Why this problem occurs: As part of addressing dotnet/aspnetcore#4849, ASP.NET Core MVC trims the suffix Async from action names by default. Starting with ASP.NET Core 3.0, this change affects both routing and link generation. See more: ASP.NET Core 3.0-3.1 | Breaking Changes | Async suffix trimmed from controller action names As @Chris … Read more

How to compile .NET Core app for Linux on a Windows machine

Using dotnet build command, you may specify –runtime flag -r|–runtime < RUNTIME_IDENTIFIER > Target runtime to build for. For a list of Runtime Identifiers (RIDs) you can use, see the RID catalog. RIDs that represent concrete operating systems usually follow this pattern [os].[version]-[arch] Fo example, to build a project and its dependencies for Ubuntu 16.04 … Read more

.NET Core RuntimeIdentifier vs TargetFramework

The <TargetFramework> (or <TargetFrameworks> when you want have multiple targets, such as net451, one or multiple netstandard1.x etc). Per <TargetFramework> / <TargetFrameworks> entry one set of assemblies will be created and located inside bin\Debug\<targetframeworkid>). This is useful, when you want to use a different library in .NET Core (because the library you used only works … Read more

ASP.NET Core JWT mapping role claims to ClaimsIdentity

You need get valid claims when generating JWT. Here is example code: Login logic: [HttpPost] [AllowAnonymous] public async Task<IActionResult> Login([FromBody] ApplicationUser applicationUser) { var result = await _signInManager.PasswordSignInAsync(applicationUser.UserName, applicationUser.Password, true, false); if(result.Succeeded) { var user = await _userManager.FindByNameAsync(applicationUser.UserName); // Get valid claims and pass them into JWT var claims = await GetValidClaims(user); // Create the … Read more

No Individual User Accounts auth option in ASP.NET Core Web API template

Individual User Accounts authentication option for the ASP.NET Core Web API is available in .NET Core 2.0 Preview 1. Unfortunately .NET Core 2.0 Preview 1 isn’t available in VS 2017 release. But you can install Visual Studio 2017 Preview (you can use it side-by-side with VS 2017 stable version) :

Uploading and Downloading large files in ASP.NET Core 3.1?

If you have files that large, never use byte[] or MemoryStream in your code. Only operate on streams if you download/upload files. You have a couple of options: If you control both client and server, consider using something like tus. There are both client- and server-implementations for .NET. This would probably the easiest and most … Read more

Correct way to return HttpResponseMessage as IActionResult in .Net Core 2.2

public class HttpResponseMessageResult : IActionResult { private readonly HttpResponseMessage _responseMessage; public HttpResponseMessageResult(HttpResponseMessage responseMessage) { _responseMessage = responseMessage; // could add throw if null } public async Task ExecuteResultAsync(ActionContext context) { var response = context.HttpContext.Response; if (_responseMessage == null) { var message = “Response message cannot be null”; throw new InvalidOperationException(message); } using (_responseMessage) { response.StatusCode … Read more