asp.net-core-mvc

How to get current model in action filter

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-18 05:41:56
问题 I have a generic action filter, and i want to get current model in the OnActionExecuting method. My current implementation is like below: public class CommandFilter<T> : IActionFilter where T : class, new() { public void OnActionExecuting(ActionExecutingContext actionContext) { var model= (T)actionContext.ActionArguments["model"]; } } It works well if my all model names are same. But i want to use differnet model names. How to solve this problem? Edit public class HomeController : Controller

How to get current model in action filter

痴心易碎 提交于 2019-12-18 05:41:12
问题 I have a generic action filter, and i want to get current model in the OnActionExecuting method. My current implementation is like below: public class CommandFilter<T> : IActionFilter where T : class, new() { public void OnActionExecuting(ActionExecutingContext actionContext) { var model= (T)actionContext.ActionArguments["model"]; } } It works well if my all model names are same. But i want to use differnet model names. How to solve this problem? Edit public class HomeController : Controller

Unable to translate bytes [FC] at index 35 from specified code page to Unicode

安稳与你 提交于 2019-12-18 04:49:08
问题 I'm trying to send an object like this to my REST API(built with asp net core) { "firstName":"tersü", "lastName":"asda" } And this is how the headers form SoapUI look: Accept-Encoding: gzip,deflate Content-Type: application/json:charset=UTF-16 Host: localhost:4004 Connection: Keep-Alive User-Agent: Apache-HttpClient/4.1.1 (java 1.5) However, my actionContext.ModelState is always invalid because it can not work with the umlaute. The exception is the following: Unable to translate bytes [FC] at

Dependency Injection (DI) in ASP.NET Core/MVC 6 ViewModel

自作多情 提交于 2019-12-18 03:48:12
问题 I'm successfully using ASP.NET 5/MVC 6 DI in my controllers using Constructor Injection. I now have a scenario where I want my View Models to utalise a service in the Validate method when implementing the IValidatableObject. Constructor injection in the ViewModel does not work because they need a default parameterless constructor. Validation Context.GetService does not work either. public IEnumerable<ValidationResult> Validate(ValidationContext validationContext) { MyService myService =

Raw SQL queries and Entity Framework Core

旧时模样 提交于 2019-12-18 03:23:13
问题 I migrate my application to ASP.NET MVC Core and Entity Framework Core and i found problem. I have raw SQL query to entity like this var rawSQL = dbContext.Database.SqlQuery<SomeModel>("Raw SQL Query").ToList(); But there is no SqlQuery<T> in context.Database . Do you have solution for this problem? 回答1: Make sure you add using Microsoft.Data.Entity; because there is an extension method you could use. var rawSQL = dbContext.SomeModels.FromSql("your SQL"); Even better, instead using raw SQL

Raw SQL queries and Entity Framework Core

时光怂恿深爱的人放手 提交于 2019-12-18 03:23:05
问题 I migrate my application to ASP.NET MVC Core and Entity Framework Core and i found problem. I have raw SQL query to entity like this var rawSQL = dbContext.Database.SqlQuery<SomeModel>("Raw SQL Query").ToList(); But there is no SqlQuery<T> in context.Database . Do you have solution for this problem? 回答1: Make sure you add using Microsoft.Data.Entity; because there is an extension method you could use. var rawSQL = dbContext.SomeModels.FromSql("your SQL"); Even better, instead using raw SQL

HttpRequest not aborted (cancelled) on browser abort in ASP.NET Core MVC

一个人想着一个人 提交于 2019-12-18 03:14:41
问题 I wrote the following MVC Controller to test cancellation functionality: class MyController : Controller { [HttpGet("api/CancelTest")] async Task<IActionResult> Get() { await Task.Delay(1000); CancellationToken token = HttpContext.RequestAborted; bool cancelled = token.IsCancellationRequested; logger.LogDebug(cancelled.ToString()); return Ok(); } } Say, I want to cancel the request, so the value ' true ' is logged in the controller action above. This is possible server-side if the server

How to use bower packages in Visual Studio 2017

≯℡__Kan透↙ 提交于 2019-12-18 03:05:52
问题 Face two difficulties with bower package manager in vs2017 In Visual Studio 2017, can not find any .bowerrc file under bower.json , so how to set the directory property? After Installation via Manage Bower Packages UI , packages store files in bower_components folder How to use those packages, as in previous versions like VS 2013 write syntax in BundleConfig.cs to manage client packages like below. Now in VS 2017, how to use those packages in a C# Core 2 ASP.NET MVC project? BundleConfig.cs :

how to implement google login in .net core without an entityframework provider

馋奶兔 提交于 2019-12-18 02:58:13
问题 I am implementing Google login for my .net core site. In this code var properties = signInManager.ConfigureExternalAuthenticationProperties("Google", redirectUrl); return new ChallengeResult("Google", properties); I need a signInManager which is (by the code example) this: private SignInManager<AppUser> signInManager; I inject it via the constructor, and then I get this error: Unable to resolve service for type 'Microsoft.AspNetCore.Identity.SignInManager1[AppUser]' while attempting to

Can Policy Based Authorization be more dynamic?

荒凉一梦 提交于 2019-12-18 02:20:12
问题 Net Core policy authorization, however it is looking very static to me. Because in the Enterprise Application, there is an often need for new roles which will need new policies (as far as i understand) or if you want to implement new type of policy specific for certain client. For example if we are building an CMS which will be driven by those policies, we will want, each client to be able to define hes own. So can this new policy base mechanism be more dynamic or, it's idea is entire