asp.net-core-webapi

ASP.NET Core Authorize attribute not working with JWT

主宰稳场 提交于 2020-01-23 04:16:37
问题 I want to implement JWT-based security in ASP.Net Core. All I want it to do, for now, is to read bearer tokens in the Authorization header, and validate them against my criteria. I don't need (and don't want) to include ASP.Net Identity. In fact, I'm trying to avoid using as many of the things that MVC adds in as possible, unless I really need them. I've created a minimal project, which demonstrates the problem. To see the original code, just look through the edit history. I was expecting

Cannot access a disposed object for DbContext in .NET Core for Async method

别说谁变了你拦得住时间么 提交于 2020-01-23 02:59:12
问题 I am having a weird problem in one of my microservice web api. My async GET methods throw a Cannot access a disposed object exception for my DbContext except for the very first time they are invoked. I tried looking online for an answer but nothing worked. I made sure my methods are not async void and I await the necessary calls. Since my POST and DELETE methods work fine, I am fairly certain that the real culprit is the IMapper instance. I think it might always point to the first instance of

MediatR when and why I should use it? vs 2017 webapi [closed]

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-22 04:57:24
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 5 months ago . It might have been asked before but I cannot find even in the official site why I should use MediatR and what problems it solves? Is it because I can pass a single object in my constructor rather than a multitude of Interfaces? Is it a replacement or competitor of ServicesBus etc

MediatR when and why I should use it? vs 2017 webapi [closed]

你离开我真会死。 提交于 2020-01-22 04:57:08
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 5 months ago . It might have been asked before but I cannot find even in the official site why I should use MediatR and what problems it solves? Is it because I can pass a single object in my constructor rather than a multitude of Interfaces? Is it a replacement or competitor of ServicesBus etc

Entity Framework Core: Include many-to-many related objects in WebAPI

試著忘記壹切 提交于 2020-01-21 09:07:07
问题 I'm not too familiar with the .NET framework but decided to try out ASP.NET Core and EF Core. I want to make a pretty simple Web API backend but I'm having trouble working with many-to-many relationships. I understand that I need to make a relationship table for the two entities, as in the example from this post: How to create a many to many relationship with latest nightly builds of EF Core? I also have my model builder creating the relationship as described here http://ef.readthedocs.io/en

Determine port in asp.net core

自闭症网瘾萝莉.ら 提交于 2020-01-21 09:01:28
问题 I want to make some microservices with asp.net core (Web Api) For service discovery I want use Consul where I must register the services via the HTTP API including IP and port. My question is: How can I know which port is used within in a service? Is there a way to determine the used port via code? 回答1: Yeah, Use HttpContext.Connection.LocalPort to get the local port that the server is listening on. 来源: https://stackoverflow.com/questions/41165303/determine-port-in-asp-net-core

Determine port in asp.net core

本秂侑毒 提交于 2020-01-21 09:00:22
问题 I want to make some microservices with asp.net core (Web Api) For service discovery I want use Consul where I must register the services via the HTTP API including IP and port. My question is: How can I know which port is used within in a service? Is there a way to determine the used port via code? 回答1: Yeah, Use HttpContext.Connection.LocalPort to get the local port that the server is listening on. 来源: https://stackoverflow.com/questions/41165303/determine-port-in-asp-net-core

Returned object has null/empty ICollection unless it is accessed/inspected first

≯℡__Kan透↙ 提交于 2020-01-17 02:37:11
问题 Seeding deserialised JSON data in the Context and then attempting to return the DbSet. api/module returns all Modules with empty ICollections (null if I don't instantiate them), where as the Assessments happily return the virtual Module. Previous experience in MVC whereby I would have been accessing the object before it being sent to the view, so I haven't encountered this issue before. The commented out line: //Enumerable.ToList(ModuleItems.Include(mi => mi.Assessments)); Resolves the issue

asp.net web api: only during sql connection - HTTP 500 Error occurs : Local host is currently unable to handle request

て烟熏妆下的殇ゞ 提交于 2020-01-16 08:37:32
问题 The Web Api throws HTTP 500 error when it has to reference values from sql database. https://localhost:44304/api/values This works fine. But, https://localhost:44304/api/User throws HTTP 500 Error - Local host is currently unable to handle request The API is a simple test one, which has to retrieve data from User table in SQL database. private readonly string connectionString = "Server=MyServerName\\SQLEXPRESS;Database=MyDatabase;Trusted_Connection=True;user id=dbuser;password=dbuserpass;";

.Net Core Web API --Redirect to external url from Post Method

久未见 提交于 2020-01-16 05:29:05
问题 Please advice how to redirect to external url from Post method using .Net core webapi. RedirectPermanent is not working. public class RegisterUserController : Controller { public async Task<RedirectResult> Post([FromBody] user) { ---somecode string url = "http://www.gmail.com"; return RedirectPermanent(url) ;//--is not working } } 回答1: For redirect to specific URL use the RedirectResult class: public async Task<ActionResult> Post([FromBody] user) { //... string url = "http://www.example.com";