asp.net-core-mvc

Is it possible/sensible to split ASP.Net Core 2 (.NET Framework) Web Api into Class Library and Hosting projects?

我的梦境 提交于 2019-12-05 04:24:21
I'm trying to port an existing WCF Web API (targeting .NET Framework 4.6.1) to ASP.Net Core 2 using Visual Studio 2017 (v15.4.5) and am having trouble figuring out good/common/supported ways to organize projects, and what types of project they should be. For example: Single project for Server and Hosting, or Class Library for Server and Console application for Hosting Windows Classic Desktop project for Console application and (new style csproj) Web Application for Server library, or both Web Applications (one outputting a Class Library, the other a Console Application) I have the sneaking

How to access session from a view in ASP .NET Core MVC 1.0

六月ゝ 毕业季﹏ 提交于 2019-12-05 03:48:24
I am trying to access session data from inside a view. Use Case: I'm storing status messages in the session that will be displayed at the top of the page. Currently I implemented this by using a DisplayMessages() function that sets some ViewData[....] properties and calling it at the beginning of every controller action. Goal: I want to only set the status message once without needing additional code in the controller to display the messages on the next page load. So I'm trying to access the messages that are stored in the session directly from the view. So far I have tried the following:

ASP.NET Core Posting Array Object JSON

江枫思渺然 提交于 2019-12-05 03:42:33
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" }, { "openTime": "08:00", "closedTime": "17:30", "id": "5" }, { "openTime": "08:00", "closedTime": "17

Returning ObjectResult results in 406 Not Acceptable

牧云@^-^@ 提交于 2019-12-05 03:24:40
While following along with Scott Allen's Pluralsight course, "Asp.net Core 1.0 Fundamentals", in the "Controllers in the MVC Framework" module and "Action Results" section I ran into a 406 Not Acceptable error on my Index action method that returned an ObjectResult with a model object. This blog post led me to making a reference to the IMvcCoreBuilder and adding the JSON formatter as follows: public void ConfigureServices(IServiceCollection services) { var mvcCore = services.AddMvcCore(); mvcCore.AddJsonFormatters(); services.AddSingleton(provider => Configuration); services.AddSingleton

ASP.NET Core MVC application insights stopped working after upgrade to .NET Core 1.1.1

我只是一个虾纸丫 提交于 2019-12-05 03:19:16
I have one simple ASP.NET Core application I was working on back in December 2016. It worked just fine with application insights and telemetry. Now after 4 months I wanted to pick up this work and started with upgrade from .NET Core 1.1.0 to 1.1.1. In this process package Microsoft.ApplicationInsights.AspNetCore got updated from version 1.0.2 to version 2.0.0 . This unfortunately caused my app to stop working, in particular I get this error: An error occurred during the compilation of a resource required to process this request. Please review the following specific error details and modify

MVC Core IActionResult meaning

瘦欲@ 提交于 2019-12-05 03:16:40
问题 What is an IActionResult ? I tried looking at MSDN and other sites, but need general, common easy to understand answer. MSDN IActionResult Example: public IActionResult About() { ViewData["Message"] = "About Page"; return View(); } 回答1: In general terms IActionResult type is a base abstraction of an action result. It is used as the base of other derived action results that represent specific response types, of which there are many. Reference Asp.Net Core Action Results Explained IActionResult

MVC 6 Web Api: Resolving the location header on a 201 (Created)

我们两清 提交于 2019-12-05 02:46:13
In Web Api 2.2, we could return the location header URL by returning from controller as follows: return Created(new Uri(Url.Link("GetClient", new { id = clientId })), clientReponseModel); Url.Link(..) would resolve the resource URL accordingly based on the controller name GetClient : In ASP.NET 5 MVC 6's Web Api, Url doesn't exist within the framework but the CreatedResult constructor does have the location parameter: return new CreatedResult("http://www.myapi.com/api/clients/" + clientId, journeyModel); How can I resolve this URL this without having to manually supply it, like we did in Web

Html.GetEnumSelectList - Getting Enum values with spaces

房东的猫 提交于 2019-12-05 02:43:30
I was using asp-items="@Html.GetEnumSelectList(typeof(Salary))" in my Razor view with a select tag, to populate the list values based on the enum Salary . However, my enum contains some items which I would like to have spaces within. E.g. one of the items is PaidMonthly , but when I display this using Html.GetEnumSelectList , I would like it to be displayed as "Paid Monthly" (with a space in it) I tried using the Description attribute over each member in the enum, however when the select box renders it uses the raw value only. Can anyone please help me out with this matter? (My Code sample) ->

IHostingEnvironment.WebRootPath is null when using EF7 commands

大城市里の小女人 提交于 2019-12-05 02:16:07
Problem When I try to add a migration to my code, e.g: dnx ef migrations add initial , the env.WebRootPath in Startup(IHostingEnvironment env) is null. This will give me compilation errors when adding a new migration or updating the database. The Code In the Startup.cs class I have these lines in the constructor: public Startup(IHostingEnvironment env) { // ... MyStaticClass.Initialize(env.WebRootPath); // ... _hostingEnvironment = env; } Here env.WebRootPath is null and in the Initialize function this throws an exception. In the ConfigureServices function of the Startup.cs I resolve my class

Client Side Deep Links with WebpackDevMiddleware 404s

女生的网名这么多〃 提交于 2019-12-05 01:26:20
I am using the WebpackDevMiddleware for Development builds to serve up a Vue.js application that uses client-side routing. The SPA application is served up from the root url just fine, but if I attempt to use any client-side deep links, I get a 404. Note running as Production works as expected. What I want: http://locahost/ - serve up the vue app. http://localhost/overlays/chat - serve up the vue app. http://localhost/api/* - serve up the api routes handled server side. There is a minimum viable reproduction of the problem in this repository . You can run it using vscode debugging as