asp.net-core-webapi

Asp.Net Core Web API 2.2 Controller not returning complete JSON

爷,独闯天下 提交于 2019-12-01 17:30:12
I have a Web API Controller in my Asp.Net Core Web API 2.2 project. Messageboard model: public class MessageBoard { public long Id { get; set; } public string Name { get; set; } public string Description { get; set; } public ICollection<Message> Messages { get; set; } } Message model: public class Message { public long Id { get; set; } public string Text { get; set; } public string User { get; set; } public DateTime PostedDate { get; set; } public long MessageBoardId { get; set; } [ForeignKey("MessageBoardId")] public MessageBoard MessageBoard { get; set; } } This is one of my Web API

Return an image from asp.net web api core as IActionResult

徘徊边缘 提交于 2019-12-01 16:49:14
问题 What is the best way to return an image file as IActionResult while using asp.net web api core? I tried returning a base64 string and it works fine. But not considered as efficient. Is there a way using which we can return an image file object itself as IActionResult. 回答1: You can use the various overloads of the File() function in controllers that inherit from Controller or ControllerBase . For example, you can do: return File("~/Images/photo.jpg", "image/jpeg"); This uses a virtual path,

Asp.Net Core Web API 2.2 Controller not returning complete JSON

牧云@^-^@ 提交于 2019-12-01 16:12:47
问题 I have a Web API Controller in my Asp.Net Core Web API 2.2 project. Messageboard model: public class MessageBoard { public long Id { get; set; } public string Name { get; set; } public string Description { get; set; } public ICollection<Message> Messages { get; set; } } Message model: public class Message { public long Id { get; set; } public string Text { get; set; } public string User { get; set; } public DateTime PostedDate { get; set; } public long MessageBoardId { get; set; } [ForeignKey

Set dummy IP address in integration test with Asp.Net Core TestServer

妖精的绣舞 提交于 2019-12-01 15:19:01
I have a C# Asp.Net Core (1.x) project, implementing a web REST API, and its related integration test project, where before any test there's a setup similar to: // ... IWebHostBuilder webHostBuilder = GetWebHostBuilderSimilarToRealOne() .UseStartup<MyTestStartup>(); TestServer server = new TestServer(webHostBuilder); server.BaseAddress = new Uri("http://localhost:5000"); HttpClient client = server.CreateClient(); // ... During tests, the client is used to send HTTP requests to web API (the system under test) and retrieve responses. Within actual system under test there's some component

Increase max url length in asp.net core

安稳与你 提交于 2019-12-01 08:54:28
问题 I have an asp.net core web api, that enables tts requests. You basically request http://server.url/Whatever you want it to say.mp3 to get an mp3 with the text spoken in tts. But the problem is, that it will return a 400 - The request URL is invalid if I pass it a long string. It seems like the server is hitting some sort of max URL length limitation. I can find information on how to fix this is the "classic" asp.net web.config, but not how to fix this in asp.net core. What is the correct way

Add user claims to firebase auth from asp.net core api

巧了我就是萌 提交于 2019-12-01 08:25:58
Given an asp.net core api and working firebase auth using only the [Authorize] attribute, how can I add custom claims to the token to use [Authorize(Policy = "admin")]? The admin SDK is only available for node.js, Java, python or go and I can't find any docs on how to use the Firebase Admin API directly. From my understanding the user claims have to be stored in the Firebase Auth backend. Since the Firebase Admin .NET SDK 1.1 is released the Control Access With Custom Claims feature is supported. You can find the repository here: https://github.com/firebase/firebase-admin-dotnet Setup guide

How to redirect to action in ASP.NET Core WebAPI?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-01 08:13:24
I've got two actions in my ASP.NET Core Web API application's controller: [HttpGet("get-all")] public IActionResult GetAll() { ... } and [HttpDelete("{id}")] public IActionResult Delete(int id) { ... return RedirectToAction("GetAll"); } Delete action always redirects to itself and never to GetAll . Why so? In the same time similar redirect from Post action works ok. Can't find any docs on the subject. Any help? Have you tried to use RedirectToActionResult? Like this (change ControllerName with your actual Controller's name ): RedirectToActionResult("GetAll", "ControllerName", null);

.NET Core 1.0 Web Api processing request body as JSON when content-type is text/plain

你。 提交于 2019-12-01 08:09:54
问题 A vendor API I need to use is sending a POST request with content-type: text/plain and JSON in the body. How do I parse it in .net core 1.0 web api? I'm sure I need to do something similar to this (code below) answer, but I don't know how in web api. public class RawContentTypeMapper : WebContentTypeMapper { public override WebContentFormat GetMessageFormatForContentType(string contentType) { switch (contentType.ToLowerInvariant()) { case "text/plain": case "application/json": return

Add user claims to firebase auth from asp.net core api

对着背影说爱祢 提交于 2019-12-01 07:16:48
问题 Given an asp.net core api and working firebase auth using only the [Authorize] attribute, how can I add custom claims to the token to use [Authorize(Policy = "admin")]? The admin SDK is only available for node.js, Java, python or go and I can't find any docs on how to use the Firebase Admin API directly. From my understanding the user claims have to be stored in the Firebase Auth backend. 回答1: Since the Firebase Admin .NET SDK 1.1 is released the Control Access With Custom Claims feature is

WebApi giving 404 whilst debugging; works when published

痴心易碎 提交于 2019-12-01 07:03:34
I have a console application written in .NET Core 2.2.6 that is using Kestrel to host a simple WebApi. public class SettingsController : Controller { // // GET: /settings/ public string Index() { return $"Hello world! controller"; } } If I publish the code and run the executable, I can visit http://127.0.0.1:310/settings and see the expected "Hello world! controller". However, if I debug (or even open in Release mode) from inside Visual Studio 2019, the same URL throws a 404 exception. Some other code that might help pinpoint the problem: public static IWebHostBuilder CreateWebHostBuilder