asp.net-core-mvc

Returning ObjectResult results in 406 Not Acceptable

ε祈祈猫儿з 提交于 2019-12-22 04:15:29
问题 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. 回答1: 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()

IHostingEnvironment.WebRootPath is null when using EF7 commands

谁都会走 提交于 2019-12-22 04:11:12
问题 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

IHostingEnvironment.WebRootPath is null when using EF7 commands

一曲冷凌霜 提交于 2019-12-22 04:11:12
问题 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

Html.GetEnumSelectList - Getting Enum values with spaces

房东的猫 提交于 2019-12-22 04:07:14
问题 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

Cannot start ASP.NET Core RC2 web application in IISExpress

和自甴很熟 提交于 2019-12-22 03:47:21
问题 I created a new "ASP.NET Core Web Application (.NET Core)" project in VS2015. It built without any issues, so I thought to give it a test run. However, when starting up, it choked and crashed with the following error: Exception thrown: 'System.AggregateException' in Microsoft.AspNetCore.Server.Kestrel.dll The program '[11608] dotnet.exe' has exited with code -1073741819 (0xc0000005) 'Access violation'. The program '[15048] iisexpress.exe' has exited with code 0 (0x0). I don't see anything

Cannot start ASP.NET Core RC2 web application in IISExpress

大兔子大兔子 提交于 2019-12-22 03:45:34
问题 I created a new "ASP.NET Core Web Application (.NET Core)" project in VS2015. It built without any issues, so I thought to give it a test run. However, when starting up, it choked and crashed with the following error: Exception thrown: 'System.AggregateException' in Microsoft.AspNetCore.Server.Kestrel.dll The program '[11608] dotnet.exe' has exited with code -1073741819 (0xc0000005) 'Access violation'. The program '[15048] iisexpress.exe' has exited with code 0 (0x0). I don't see anything

How to consistently get application base path for ASP.NET 5 DNX project on both production and development environment?

那年仲夏 提交于 2019-12-22 03:40:54
问题 I have deployed a ASP.NET MVC 6 website to Azure from Git. Details of the deployment can be found in this blog post but basically I use DNU to publish it and then kudu to push it to an Azure website. Using IHostingEnvironment I get the ApplicationBasePath. The problem is that the paths I get back are very different on localhost and on Azure. Azure: "D:\home\site\approot\src\src" Localhost: "C:\Users\deebo\Source\mysite\site\src" I want to use the base path to get the full path to a folder

How to consistently get application base path for ASP.NET 5 DNX project on both production and development environment?

给你一囗甜甜゛ 提交于 2019-12-22 03:40:04
问题 I have deployed a ASP.NET MVC 6 website to Azure from Git. Details of the deployment can be found in this blog post but basically I use DNU to publish it and then kudu to push it to an Azure website. Using IHostingEnvironment I get the ApplicationBasePath. The problem is that the paths I get back are very different on localhost and on Azure. Azure: "D:\home\site\approot\src\src" Localhost: "C:\Users\deebo\Source\mysite\site\src" I want to use the base path to get the full path to a folder

MVC 6 IUrlHelper Dependency Injection

好久不见. 提交于 2019-12-22 03:24:56
问题 I want to use IUrlHelper through dependency injection to be able to use its functionality to generate uris for different rest endpoints. I cant seem how to figure out how to create a UrlHelper from scratch because it changed in MVC 6 and MVC doesnt automatically have that service available in the IoC controller. The setup is my Controller take in an internal model to api model converter class and that uses the IUrlHelper (all through Depenedency Injection). If there is a better alternative to

Checking login user AuthorizePolicy in Razor page on Asp.Net Core

╄→尐↘猪︶ㄣ 提交于 2019-12-22 01:51:05
问题 I'm looking for a variant of this @if (SignInManager.IsSignedIn(User) && User.IsInRole(Roles.Administrator)) { <div id="editArticle"> but instead of checking after the role I'm after a check into the policy much like you would in a controller by doing this. [Authorize(Policy = Policies.RequireAdmin)] 回答1: This seems similar to question asked here I found this link which may be helpful: https://docs.asp.net/en/latest/security/authorization/views.html Examples from that page: @if (await