asp.net-core-webapi

Host RestAPI inside IIS

喜夏-厌秋 提交于 2019-12-10 09:43:28
问题 I have a rather simple .NET WebApi application which I'm trying to host inside IIS. Followed all of the instructions from MS site about this. here is the startup method for it. public static void Main(string[] args) { var host = WebHost.CreateDefaultBuilder(args) .UseKestrel() .UseContentRoot(Directory.GetCurrentDirectory()) .UseIISIntegration() .UseStartup<Startup>() .Build(); host.Run(); } I configured the Application pool to not use any managed code but I'm getting still this error in logs

Is services.AddSingleton<IConfiguration> really needed in .net core 2 API

有些话、适合烂在心里 提交于 2019-12-10 09:24:30
问题 I accessed appsettings.json In .NET Core 2 Web API Controller simply by adding below: public class MyController : Controller { private readonly IConfiguration appConfig; public MyController(IConfiguration configuration) { appConfig = configuration; } } Without adding below in Startup class ConfigureServices(IServiceCollection services) after services.AddMvc();: services.AddSingleton<IConfiguration>(Configuration); Is there any flaws in my approach? In official docs for .Net Core 2

ASP.NET Core CreatedAtRoute No route matches the supplied values

本秂侑毒 提交于 2019-12-10 01:47:56
问题 Using ASP.NET Core 2.0.0 Web API, I'm trying to build a controller to do a database insert. The information can be inserted into the database just fine, but returning a CreatedAtRoute throws an 'InvalidOperationException: No route matches the supplied values.' Everything I've found online so far says this was a bug with early pre-release versions of ASP.NET Core and has since been fixed, but I'm not really sure what to do about this. The following is my controller code: [Produces("application

How to pass data and image both to “ASP.NET Core” Web API using Angular 2(typescript)?

Deadly 提交于 2019-12-09 16:35:50
问题 I have code that can pass data only to web API but i want to pass data and Image both in same request not in different request using angular 2 + typescript and in ASP.Net Core Web API. My Code to pass data to API: Angular Code: create(user) { return this.authHttp.post(this._baseUrl + 'user/', JSON.stringify(userData)).map((res: Response) => { return res; }).catch(this.configService.handleError); } API Code: [HttpPost] public IActionResult Create([FromBody]UserModel user) { if (!ModelState

.NET Core 2 and SwashBuckle Swagger UI is not Displaying

限于喜欢 提交于 2019-12-09 16:35:42
问题 I have followed a few tutorials and have gotten this to work at work but for some reason I am not able to get the UI to display but the Swagger Json is created. Last tutorial I looked at is here. My setup is like so: Nuget Package: Swashbuckle.AspNetCore(1.0.0) ConfigureServices Method: services.AddSwaggerGen(options => { options.SwaggerDoc("v1", new Info { Title = "MediatR Example", Version = "v1", Description = "Trying out the MediatR library to simplify Request and Response logic.",

.NET Core UseCors() does not add headers

大兔子大兔子 提交于 2019-12-09 14:20:16
问题 This would be a duplicate of How does Access-Control-Allow-Origin header work?, but the method there also isn't working for me. I'm hoping I'm just missing something. I am trying to get a Access-Control-Allow-Origin header in my response from my .NET Core Web API, which I am accessing via AJAX. I have tried several things. All, unless noted otherwise, have been in the Startup.cs file. Method 1 As per the Microsoft Documentation: public void ConfigureServices(IServiceCollection services) { //

Equivalent of HttpResponseException/IHttpActionResponse for .net Core webapi 2 (not mvc)

佐手、 提交于 2019-12-09 07:44:32
问题 When I am reading about webapi for responding to requests and handling errors everything is based around: IHttpActionResult HttpResponseException But when you create a .net core webapi project these are not available. I can find IActionResult, which seems to be the equivalent? But I'm going round in circles trying to find out a really very simple thing, which is how to handle errors in a .net core webapi because HttpResponseException is not available. I get the impression everything with

Why is IFormFile collection empty when sent from Dropzone.js?

泪湿孤枕 提交于 2019-12-08 20:47:29
I am trying to use Dropzone.js to send a collection of IFormFile (images) to the following ASP.NET Core 2.1 Api controller action: [HttpPost("[action]")] public async Task<IActionResult> Upload([FromForm] ICollection<IFormFile> files) { ... } I am able to successfully send files to this Api from Postman. But I cannot get it to send the files from my UI, which implements Dropzone. I am using an ASP form in a Razor page <div> <form action="/api/images/upload" class="dropzone needsclick dz-clickable" id="image-upload" method="post" enctype="multipart/form-data"> <div class="dz-message needsclick"

ASP.NET Core API Controller: Response.Body.WriteAsync base64 string not working

你说的曾经没有我的故事 提交于 2019-12-08 16:51:18
问题 I'm trying to return a base64 string representing a jpeg image from an API Controller and set it as the src of an <img> but all my attempts failed. Here is the very simple HTML: <img src="/api/TestBase64Image" alt="image test" /> And my controller: [Route("api/[controller]")] public class TestBase64ImageController : Controller { private const string _base64Image = "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEBLAEsAAD/7Sfg....."; private const string _base64Image2 = "/9j/4AAQSkZJRgABAQEBLAEsAAD

add-migration : Cannot bind argument to parameter 'Path' because it is an empty string

时光总嘲笑我的痴心妄想 提交于 2019-12-08 16:27:38
问题 I'm running default api core project on Visual studio 2017 with docker support and I got this error everytime I run the command add-migration -name name add-migration : Cannot bind argument to parameter 'Path' because it is an empty string. At line:1 char:1 + add-migration + ~~~~~~~~~~~~~ + CategoryInfo : InvalidData: (:) [Add-Migration], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,Add-Migration PS : This command works