asp.net-core-webapi-2.1

“500 - Internal server error” when calling ASP .Net Core 2.1 Web API on Windows Server

守給你的承諾、 提交于 2021-02-19 04:32:38
问题 I have an ASP .Net Core 2.1 Web API which I've deployed to a new server we recently purchased (running Windows Server 2016 Standard). The API works perfectly on both my development PC and our old server (running Windows Server 2012 R2). But on this new server, I get this error: 500 - Internal server error. There is a problem with the resource you are looking for, and it cannot be displayed. I remember a year ago also struggling a lot trying to get it to run on our old server. I did eventually

Detected package version outside of dependency constraint :Microsoft.AspNetCore.App 2.1.1

左心房为你撑大大i 提交于 2020-08-21 17:49:40
问题 I am trying to install some packages in my API using : Install-Package Microsoft.EntityFrameworkCore.SqlServer It throws an Error (Given below ) : NU1608: Detected package version outside of dependency constraint: Microsoft.AspNetCore.App 2.1.1 requires Microsoft.EntityFrameworkCore.SqlServer (>= 2.1.1 && < 2.2.0) but version Microsoft.EntityFrameworkCore.SqlServer 2.2.0 was resolved. Install-Package : NU1107: Version conflict detected for Microsoft.EntityFrameworkCore. Install/reference

Detected package version outside of dependency constraint :Microsoft.AspNetCore.App 2.1.1

故事扮演 提交于 2020-08-21 17:41:23
问题 I am trying to install some packages in my API using : Install-Package Microsoft.EntityFrameworkCore.SqlServer It throws an Error (Given below ) : NU1608: Detected package version outside of dependency constraint: Microsoft.AspNetCore.App 2.1.1 requires Microsoft.EntityFrameworkCore.SqlServer (>= 2.1.1 && < 2.2.0) but version Microsoft.EntityFrameworkCore.SqlServer 2.2.0 was resolved. Install-Package : NU1107: Version conflict detected for Microsoft.EntityFrameworkCore. Install/reference

Implement Pagination in ASP.NET Core 2.1 Web API

佐手、 提交于 2020-02-02 02:48:09
问题 I searched, but did't really found articles on how to implement pagination logic in an ASP.NET WebAPI Core 2.1 application... I have the following [Route("api/[controller]")] [ApiController] [EnableCors("AllowMyOrigin")] public class EntriesController : ControllerBase { private readonly EntriesContext _context; public EntriesController(EntriesContext context) { _context = context; if (_context.Entries.Count() == 0) { _context.Entries.Add(new Entry { From = "default", To = "default" });

Log to Event Viewer in an ASP .Net Core 2.1 Web API

我是研究僧i 提交于 2019-12-11 02:52:56
问题 I'm trying to log to the Event Viewer in an ASP .Net Core 2.1 Web API, hosted on Windows Server 2016 Standard. I've got this in my controller: private readonly ILogger<MyController> _logger; private readonly MyContext _context; public TestController(MyContext context, ILogger<MyController> logger) { _context = context; _logger = logger; } But I think I'm doing something wrong in my CreateWebHostBuilder() method in Program.cs because it's not working: I had this: public static IWebHostBuilder

How to generate the appsettings.<EnvironmentName>.json file?

匆匆过客 提交于 2019-12-10 22:38:01
问题 I have an asp.net core 2 web api which will be deployed across the following environments: INT, QA, STAGE, PRODUCTION environments. Based on the above, I need to have appsettings.<EnvironmentName>.json file for each environment. From the link : https://docs.microsoft.com/en-us/aspnet/core/fundamentals/environments?view=aspnetcore-2.1 , I see that In case of local development environment, the Environment Variable called ASPNETCORE_ENVIRONMENT is set to Development. In case of the deployment

Enum as Required Field in ASP.NET Core WebAPI

為{幸葍}努か 提交于 2019-12-10 17:33:42
问题 Is it possible to return the [Required] attribute error message when a JSON request doesn't provide a proper value for an enum property? For example, I have a model for a POST message that contains an AddressType property that is an enumeration type: public class AddressPostViewModel { [JsonProperty("addressType")] [Required(ErrorMessage = "Address type is required.")] public AddressType AddressType { get; set; } } The AddressType enum accepts two values: [JsonConverter(typeof

IFormFile is always null when receiving file from console app

梦想的初衷 提交于 2019-12-06 11:41:26
问题 I have my WebApi method ready to accept file as parameter shown below: (e.g. uri "https://localhost:44397/api/uploadfile" [Route("api/[controller]")] [ApiController] public class UploadFileController : ControllerBase { [HttpPost] public async Task<IActionResult> Post([FromForm] IFormFile file) { } } Am using console app to send file to this api method, below is my code: public static void Send(string fileName) { using (var client = new HttpClient()) using (var content = new

IFormFile is always null when receiving file from console app

假如想象 提交于 2019-12-04 18:42:14
I have my WebApi method ready to accept file as parameter shown below: (e.g. uri " https://localhost:44397/api/uploadfile " [Route("api/[controller]")] [ApiController] public class UploadFileController : ControllerBase { [HttpPost] public async Task<IActionResult> Post([FromForm] IFormFile file) { } } Am using console app to send file to this api method, below is my code: public static void Send(string fileName) { using (var client = new HttpClient()) using (var content = new MultipartFormDataContent()) { client.BaseAddress = new Uri("https://localhost:44397"); var fs = new FileStream(fileName