asp.net-core-webapi

ready to use uint route constraint?

陌路散爱 提交于 2020-06-16 18:35:24
问题 I have a .NET Core Web API project and my Ids are integers starting at 1. In most samples I see something like this [HttpGet("{id:int}")] public async Task<ActionResult<User>> GetUserByIdAsync([FromRoute] int id) { // ... } Since I know Ids must be greater than 0 I also added the :min(1) route constraint. But wouldn't it be better to change the integer datatype to uint ? The route would then be "{id:uint:min(1)}" and the method parameter will change to [FromRoute] uint id but unfortunately

ASP.Net Core: set default culture from controller

不想你离开。 提交于 2020-06-16 17:16:09
问题 I am trying to set up localization in my ASP.Net Core Web API project. I did some research and understand that there is a localization middleware with predefined request culture providers (which in my case are not acceptable), so I need to write a custom request culture provider, something like public class CustomCultureProvider : RequestCultureProvider { public override async Task<ProviderCultureResult> ChangeCulture(HttpContext httpContext) { // Return a culture... return new

ASP.Net Core: set default culture from controller

廉价感情. 提交于 2020-06-16 17:16:05
问题 I am trying to set up localization in my ASP.Net Core Web API project. I did some research and understand that there is a localization middleware with predefined request culture providers (which in my case are not acceptable), so I need to write a custom request culture provider, something like public class CustomCultureProvider : RequestCultureProvider { public override async Task<ProviderCultureResult> ChangeCulture(HttpContext httpContext) { // Return a culture... return new

ASP.NET core web api returns 404 when Startup.cs in different assembly

ぐ巨炮叔叔 提交于 2020-06-16 05:09:10
问题 I have .net core web API and when I isolated Startup.cs in different assembly all APIs return 404 and if I return Startup.cs back to the same assembly where controllers exist, they work again. Here is my Program.cs of my web API: public class Program { public static void Main(string[] args) { CreateWebHostBuilder(args).Build().Run(); } public static IWebHostBuilder CreateWebHostBuilder(string[] args) => WebHost.CreateDefaultBuilder(args) .UseStartup<Startup>() .ConfigureAppConfiguration(

ASP.NET core web api returns 404 when Startup.cs in different assembly

不想你离开。 提交于 2020-06-16 05:07:44
问题 I have .net core web API and when I isolated Startup.cs in different assembly all APIs return 404 and if I return Startup.cs back to the same assembly where controllers exist, they work again. Here is my Program.cs of my web API: public class Program { public static void Main(string[] args) { CreateWebHostBuilder(args).Build().Run(); } public static IWebHostBuilder CreateWebHostBuilder(string[] args) => WebHost.CreateDefaultBuilder(args) .UseStartup<Startup>() .ConfigureAppConfiguration(

How to send a message to service bus topic from .net core application

限于喜欢 提交于 2020-06-16 04:18:21
问题 I've created API using .net core application, which is used to send set of properties to the SQL DB and also one copy of the message should be sent to the azure service bus topic. As of now .net core doesn't support service bus. Kindly share your thoughts. How can I send the messages to the service bus topic using .net core application? public class CenterConfigurationsDetails { public Guid Id { get; set; } = Guid.NewGuid(); public Guid? CenterReferenceId { get; set; } = Guid.NewGuid();

How can I get my .NET Core 3 single file app to find the appsettings.json file?

可紊 提交于 2020-06-09 16:59:06
问题 How should a single-file .Net Core 3.0 Web API application be configured to look for the appsettings.json file that is in the same directory that the single-file application is built to? After running dotnet publish -r win-x64 -c Release /p:PublishSingleFile=true The directory looks like this: XX/XX/XXXX XX:XX PM <DIR> . XX/XX/XXXX XX:XX PM <DIR> .. XX/XX/XXXX XX:XX PM 134 appsettings.json XX/XX/XXXX XX:XX PM 92,899,983 APPNAME.exe XX/XX/XXXX XX:XX PM 541 web.config 3 File(s) 92,900,658 bytes

Partial content in .NET Core MVC (for video/audio streaming)

こ雲淡風輕ζ 提交于 2020-06-07 21:19:28
问题 I am trying to implement video and audio streaming on my website (to enable seeking in Chrome) and I recently found out that .NET Core 2.0 apparently provides a relatively simple and recommended way of implementing this using FileStreamResult . This is my simplified implementation of the Action that returns the FileStreamResult: public IActionResult GetFileDirect(string f) { var path = Path.Combine(Defaults.StorageLocation, f); return File(System.IO.File.OpenRead(path), "video/mp4"); } The

Curl 415 Unsupported Media Type

廉价感情. 提交于 2020-05-30 09:21:44
问题 I am trying to test my endpoint with curl and getting a 415: curl -X POST "http://localhost:5001/api/countries/import" \ --header "Content-Type: application/json" \ --header "Authorization: Bearer "$API_TOKEN \ --data @/D:/_countries.json Response: {"type":"https://tools.ietf.org/html/rfc7231#section-6.5.13","title":"Unsupported Media Type","status":415,"traceId":"0HLTFOME7T990:00000001"} And here's my .net core endpoint: // POST api/countries/import [HttpPost] [Route("[action]")] public

AspNet core web Api usage of ApiControllerAttribute

和自甴很熟 提交于 2020-05-29 07:17:31
问题 When I create a new controller in the API project, it generates a controller class with [ApiController] attribute, like this: [ApiController] public class TestController : ControllerBase { //implementation } I've seen a few webapi projects where usage of this attribute is omitted. Microsoft documentation here says: Indicates that a type and all derived types are used to serve HTTP API responses. The presence of this attribute can be used to target conventions, filters and other behaviors