asp.net-core-2.1

Connection ID when calling SignalR Core Hub method from Controller

拟墨画扇 提交于 2019-12-01 23:40:11
This is a follow-up to another question and answer . What's the effect of calling HubContext.Clients.Caller or HubContext.Clients.Others from the controller? I see it depends on the connection ID . What value would it have in this situation? If the connection ID (and thus Caller and Others ) is invalid then (from within the controller action) how could I obtain a connection ID (for the client currently calling the Web API) that I could use with HubContext.Clients 's methods? What's the effect of calling HubContext.Clients.Caller or HubContext.Clients.Others from the controller? I see it

How do I unit test model validation in controllers decorated with [ApiController]?

我的未来我决定 提交于 2019-12-01 22:52:07
As pointed out in this anwer to Asp.Net Core 2.1 ApiController does not automatically validate model under unit test , the automatic ModelState validation that ASP.NET Core 2.1's ApiControllerAttribute gives us only works when actualyy requestion the action at runtime, not by calling it with an invalid parameter in a unit test. However, I still want to test if my action actually returns a BadRequestResult when supplying an incorrect model. Is there any way of doing this? I get that I can still manually check if ModelState.IsValid is false, and returning BadRequest() myself, but that kind of

Custom UserManager always return null

穿精又带淫゛_ 提交于 2019-12-01 21:31:34
问题 I am trying to create my own UserManager extending from the original, and when I do a search by email, the user is not found. But if I do a search from the context, if I find the user (see the Get method). To verify that it is really well implemented, I overwrote the FindByEmailAsync method and it is really being called, but I do not know why the user can not find it. Some help? Thank you! public void ConfigureServices(IServiceCollection servicesCollection) { servicesCollection.AddDbContext

Reference to an ITVF raises a “second operation started on this context before a previous operation completed” exception

社会主义新天地 提交于 2019-12-01 21:14:53
I am attempting to reference an Inline Table-Valued Function (ITVF) in a Linq query: var results = await ( from v in _context.Vehicles from r in _context.UnitRepairStatus(v.VehicleNumber) <-- ITVF reference orderby v.VehicleNumber select new FooViewModel { ID = v.ID, VehicleNumber = v.VehicleNumber, InRepair = Convert.ToBoolean(r.InRepair) <-- ITFV field } ).ToListAsync(); When the query runs, it generates an error: InvalidOperationException: A second operation started on this context before a previous operation completed. Any instance members are not guaranteed to be thread safe. with a

XmlSerializerInputFormatter is obsolete - ASP.NET Core 2.1

风流意气都作罢 提交于 2019-12-01 16:42:06
问题 I am using the following to accept XML serialized in my Core API App. services.AddMvc(options => { // allow xml format for input options.InputFormatters.Add(new XmlSerializerInputFormatter()); }).SetCompatibilityVersion(CompatibilityVersion.Version_2_1); After updating to ASP.NET Core 2.1 I receive the following warning: 'XmlSerializerInputFormatter.XmlSerializerInputFormatter()' is obsolete: 'This constructor is obsolete and will be removed in a future version.' What is the new way to handle

ASP.Net Core 2.1 Angular SSR/Universal returning Http Status Code 404

陌路散爱 提交于 2019-12-01 13:16:33
问题 With SpaPrerenderingExtensions available in ASP.Net core 2.0 JavaScriptServices , it seems that we can return the HTTP Status Code from the Angular (SSR) App which SpaPrerenderingExtensions will use to return the HTTP Status Code to the client. If you take a look at below method in SpaPrerenderingExtensions private static async Task ServePrerenderResult(HttpContext context, RenderToStringResult renderResult) Complete code of SpaPrerenderingExtensions is available here: https://github.com

Localized page names with ASP.NET Core 2.1

偶尔善良 提交于 2019-12-01 06:55:58
问题 When create a Razor page, e.g. "Events.cshtml", one get its model name set to @page @model EventsModel where the page's name in this case is "Events", and the URL would look like http://example.com/Events To be able to use page name's in Norwegian I added the following to the "Startup.cs" services.AddMvc() .SetCompatibilityVersion(CompatibilityVersion.Version_2_1) .AddRazorPagesOptions(options => { options.Conventions.AddPageRoute("/Events", "/hvaskjer"); options.Conventions.AddPageRoute("

Proper way to register HostedService in ASP.NET Core. AddHostedService vs AddSingleton

早过忘川 提交于 2019-12-01 02:19:01
What is proper way to register custom hosted service in ASP.NET Core 2.1? For example I have custom hosted service derived from BackgroundService named MyHostedService . How should I register it? public IServiceProvider ConfigureServices(IServiceCollection services) { //... services.AddSingleton<IHostedService, MyHostedService>(); } or public IServiceProvider ConfigureServices(IServiceCollection services) { //... services.AddHostedService<MyHostedService>(); } ? Here we can see first case, but here there is second case. Are these methods equal? They are similar but not completely

IDX20803: Unable to obtain configuration from

两盒软妹~` 提交于 2019-11-30 20:23:06
I know this question has been answered, but I don't understand what people exactly do (about certificates, ssl) and they all use a localhost but not me. I used this sample as my example OpenIdConnect I'm using: A web app A web API Both are using .Net Core 2.1. The Web App is using the Azure AD connection to get a JwtBearer token, that is sent to the API. Seeing the route /api/information in the API, a request is sent from the Web App to the API, and the API is returning the error above. The exact error is: System.InvalidOperationException: IDX20803: Unable to obtain configuration from: 'https:

The application completed without reading the entire request body, .net core 2.1.1

早过忘川 提交于 2019-11-30 13:01:27
问题 I have created a user register controller to register users with repository design pattern. My controller looks like this. [Route("api/[controller]")] public class AuthController : Controller { private readonly IAuthRepository _repo; public AuthController(IAuthRepository repo) { _repo = repo; } [AllowAnonymous] [HttpPost("register")] public async Task<IActionResult> Register([FromBody] UserForRegisterDto userForRegisterDto){ // validate request if(!ModelState.IsValid) return BadRequest