asp.net-core-mvc

ASP.NET Core Posting Array Object JSON

假装没事ソ 提交于 2019-12-10 02:29:13
问题 I'm trying to post an array of Object in my view to my controller but params are null i saw that for just a simple object I need to put [FromBody] in my controller action. Here is my JSON: { "monJour": [ { "openTime": "04:00", "closedTime": "21:30", "id": "0" }, { "openTime": "08:00", "closedTime": "17:30", "id": "1" }, { "openTime": "08:00", "closedTime": "17:30", "id": "2" }, { "openTime": "08:00", "closedTime": "17:30", "id": "3" }, { "openTime": "08:00", "closedTime": "17:30", "id": "4" }

ASP.NET Core MVC View Components

China☆狼群 提交于 2019-12-10 01:29:03
问题 In ASP.NET Core MVC (formerly MVC 6) there is a new area of functionality called View Components which appear to be a better alternative to Partial Views. I've seen the following View Component Example. But there doesn't seem much more information currently as to their usage. I'm trying to evaluate if its worth using this pattern and if this can/(or is intended) to be used as a more baked in method to help with donut caching. 回答1: View components are definitively great and it's certainly an

Why is TestServer not able to find controllers when controller is in separate assembly for asp.net core app?

梦想与她 提交于 2019-12-10 01:17:39
问题 For some reason, when ASP.NET core controllers are created in separate assembly, the TestServer is not able to find controller actions when the client makes a request.(results in 404 response) Why is this? How can I work around it? Here are steps to reproduce. Create new ASP.NET Core WebAPI using .NET core Create integration tests in separate project and configure the test to use TestServer() client and get tests to work successfully. Now, separate the controller into its own shared library

ASP.Net Core, detecting debugging vs. not debugging in a controller

半城伤御伤魂 提交于 2019-12-10 01:04:54
问题 I am writing my first ASP.Net code web app and in my controller I would like to have an if statement that checks to see if I am in debugging mode or not. I know in the Startup.cs file I can check env.IsDevelopment() but that is because the IHostingEnvironment is passed into it. I have not been able to find a way to check for this status inside a normal controller. Is there a way in ASP.Net Core to detect when I am in debug mode inside the controller that I am missing? 回答1: You should be able

AOP for C# dotnet core 2.0, access method parameter values before method body runs

╄→гoц情女王★ 提交于 2019-12-09 22:38:26
问题 This is my method, I am trying to validate componentToSave (or access method parameter values) and throw an exception before method body even runs. public Component SaveComponent(Component componentToSave) { ... } I tried using PostSharp but it is not free and also there were other libraries that rely on AutoFac as IoC but in my current setup I am using dotnet core's built-in dependency injection. I tried NConcern and it relies on CNeptune and CNeptune itself relies on a .exe file for post

Token auth in asp mvc 6

霸气de小男生 提交于 2019-12-09 19:36:44
问题 It seems like there is not a lot of information about how to do authorization with the new MVC version. Since ASP 5 now is in RC 1 one could guess that you now can start trying to understand how its going to work... What I want to do is just a simple example of an auth token that contains the user's name and roles. A link like http://bitoftech.net/2015/03/11/asp-net-identity-2-1-roles-based-authorization-authentication-asp-net-web-api/ would help greatly but seems hard to find 回答1: You can

Entity Framework Core Migration for ASP.Net Core Class Library

北慕城南 提交于 2019-12-09 18:37:42
问题 I've been trying to follow the advice of Ben Cull (http://benjii.me/2016/06/entity-framework-core-migrations-for-class-library-projects), but the database is a little different in that I'm trying to inherit from ASP.NET Core IdentityUser class. I created a new solution containing the default ASP.NET Core Web Application from the VS2015 template (CodeFirstTest). I then added an ASP.NET Core class-library (CodeFirstTest.User) to the solution, which would be the data layer in the application and

ASP.NET MVC6 Beta8 & Windows Authentication

一笑奈何 提交于 2019-12-09 17:41:06
问题 After upgrading to Beta 8, debugging using the windows authentication doesn't work in IIS Express. I am getting an error "An error occurred attempting to determine the process id of the DNX process hosting your application." Steps to reproduce:. Create a new project and choose Empty web template. In the project settings, change the IIS Express settings to use Windows Authentication. Uncheck the anonymous authentication. Enable SSL. Debug the project. Error comes up. I am using new

How to inject IHttpContextAccessor into Autofac TenantIdentificationStrategy

霸气de小男生 提交于 2019-12-09 17:23:37
问题 I am migrating my multitenant application from Webapi to aspnet core. In webapi version I was using TenantIdentificationStrategy that identified tenants based on request path on HttpContext . Moving to aspnet core, I am able to wire-up autofac successfully. I am not able to figure out how to wireup the tenant strategy. I tried injecting IHttpContextAccessor in ConfigureServices as services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>(); and my strategy looks like this public class

MVC 6 RC2 Controllers in another assembly

依然范特西╮ 提交于 2019-12-09 16:16:07
问题 In MVC 6 RC1 we used the IAssemlbyProvider interface to register assemblies that were discovered at runtime and inject additional controller types, in a similar fashion to this post.. Now with RC2 release the IAssemblyProvider has been removed and has changed to (see reference). Our framework version is currently net46 . Since the upgrade our controllers in external assemblies (not referenced) are returning a 404 status. We have tried manually add the controller to the registered controllers