asp.net-core-2.1

Pager in .Net Core 2.1

ぃ、小莉子 提交于 2020-03-23 08:15:11
问题 I have added ReflectionIT.Mvc.Paging from NuGet Link but I have a problem. In a controller i have 2 methods, Index and Organizations. When I am on the view of Orginizations and press page with number "2" in controller goes to index and not on Organizations method. How to force it to go on a method I want or to extend this @await this.Component.InvokeAsync("Pager", new { pagingList = this.Model }) to pass method name as parameter? Controller: public IActionResult Index() { return View(); }

How to validate json request body as valid json in asp.net core

醉酒当歌 提交于 2020-03-16 08:08:31
问题 In asp.net core 2.1, when a controller action is set as: [HttpPost] public JsonResult GetAnswer(SampleModel question) { return Json(question.Answer); } where the SampleModel is defined as: public class SampleModel { [Required] public string Question { get; set; } public string Answer { get; set; } } this is still considered as valid request: { "question": "some question", "question": "some question 2", "answer": "some answer" } In the controller I can see that second question is the value of

How to validate json request body as valid json in asp.net core

孤街醉人 提交于 2020-03-16 08:06:30
问题 In asp.net core 2.1, when a controller action is set as: [HttpPost] public JsonResult GetAnswer(SampleModel question) { return Json(question.Answer); } where the SampleModel is defined as: public class SampleModel { [Required] public string Question { get; set; } public string Answer { get; set; } } this is still considered as valid request: { "question": "some question", "question": "some question 2", "answer": "some answer" } In the controller I can see that second question is the value of

ILoggingBuilder Logging LogLevel in Appsettings Json doesn't seem to be acknowledged in Azure Log Stream or Blob Log

*爱你&永不变心* 提交于 2020-02-28 07:09:23
问题 I've created a new .net core 2.1 web app and deployed to Azure and Log Stream and and Application Logging to Blob storage don't seem to be honoring my Logging configuration. I created a new Solution with a new project in Visual Studio 2019 for a .net core 2.1 web app. In the home controller Index route, we added a line log some information that looks like this: private readonly ILogger<HomeController> _logger; public HomeController(ILogger<HomeController> logger) { _logger = logger; } public

how to typecast Child to Parent object in C#

主宰稳场 提交于 2020-02-06 07:28:43
问题 I have an ASP.Net Core 2.1 C# application. This is how my DTOs looks like. public class Movie { public int Id { get; set;} public bool IsSpecial {get; set;} public IEnumerable<Ticket> Tickets{ get; set;} } Tickets (Base Class) public class Ticket { public int Id { get; set;} public string Name { get; set;} public decimal price { get; set;} } TicketsSpecial (Child/Derived Class) public class TicketsSpecial : Ticket { public string SpecialProp1 { get; set;} public string SpecialProp2 { get; set

Use Cors based on an appSettings in .Net Core

南笙酒味 提交于 2020-02-05 04:21:09
问题 I am updating a .net 4.5.2 project to .Net core web api. Right now, the Cors is setup as below based on an appSetting value CorsAllowAll : if ((ConfigurationManager.AppSettings["CorsAllowAll"] ?? "false") == "true") { appBuilder.UseCors(CorsOptions.AllowAll); } else { ConfigureCors(appBuilder); } private void ConfigureCors(IAppBuilder appBuilder) { appBuilder.UseCors(new CorsOptions { PolicyProvider = new CorsPolicyProvider { PolicyResolver = context => { var policy = new CorsPolicy(); policy

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" });

Is there a way to reset $id in JSON response for each HTTP Request?

◇◆丶佛笑我妖孽 提交于 2020-01-24 00:26:08
问题 XYZController.cs [HttpPost] public async Task<ActionResult> Post([FromBody] T inputContext) { var outputContext = Process(inputContext); return StatusCode(200, outputContext ); } Startup.cs public void ConfigureServices(IServiceCollection services) { services.AddMvc().AddJsonOptions(options => { UpdateJsonSettings.ConfigureJsonFormatter(options.SerializerSettings); }); } UpdateJsonSettings.cs internal static void ConfigureJsonFormatter(JsonSerializerSettings settings) { settings

How-To get details of 401 Unauthorized from ASP.NET Core 2.1 API

江枫思渺然 提交于 2020-01-23 06:55:06
问题 I am working on an ASP.NET API (built in Core 2.1) and when trying to call it from a test application, I am getting a 401 Unauthorized. However, near as I can tell, the Access Token is fine. Is there a way to get more details about what is invalid from the Authentication handler in ASP.NET Core 2.1? If I can get some idea of what is wrong with the token, I should be able to find a solution to correct it, but right now I am stumbling around in the dark and just trying various things (most

How-To get details of 401 Unauthorized from ASP.NET Core 2.1 API

孤人 提交于 2020-01-23 06:54:20
问题 I am working on an ASP.NET API (built in Core 2.1) and when trying to call it from a test application, I am getting a 401 Unauthorized. However, near as I can tell, the Access Token is fine. Is there a way to get more details about what is invalid from the Authentication handler in ASP.NET Core 2.1? If I can get some idea of what is wrong with the token, I should be able to find a solution to correct it, but right now I am stumbling around in the dark and just trying various things (most