asp.net-core-1.0

asp.net core 1.0 web api use camelcase

依然范特西╮ 提交于 2019-11-26 15:44:51
问题 On RC2 the same code returns json format with camel case. After netcore 1.0 release i started new project and the same code is returning json in lowercase. Tried multiple solutions but none of them were working web-api-serialize-properties-starting-from-lowercase-letter 回答1: services .AddMvc() .AddJsonOptions(options => { options.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.DefaultContractResolver(); }); This keeps a JSON object's name the same as .NET class

How to specify the view location in asp.net core mvc when using custom locations?

坚强是说给别人听的谎言 提交于 2019-11-26 12:24:15
问题 Let\'s say I have a controller that uses attribute based routing to handle a requested url of /admin/product like so: [Route(\"admin/[controller]\")] public class ProductController: Controller { // GET: /admin/product [Route(\"\")] public IActionResult Index() { return View(); } } Now let\'s say that I\'d like to keep my views organized in a folder structure that roughly reflects the url paths they are related to. So I\'d like the view for this controller to be located here: /Views/Admin

Error handling (Sending ex.Message to the client)

♀尐吖头ヾ 提交于 2019-11-26 10:25:28
问题 I have an ASP.NET Core 1.0 Web API application and trying to figure out how to pass the exception message to the client if a function that my controller is calling errors out. I have tried so many things, but nothing implements IActionResult . I don\'t understand why this isn\'t a common thing that people need. If there truthfully is no solution can someone tell me why? I do see some documentation out there using HttpResponseException(HttpResponseMessage) , but in order to use this, I have to

How to get the current logged in user Id in ASP.NET Core

前提是你 提交于 2019-11-26 06:58:28
问题 I\'ve done this before with MVC5 using User.Identity.GetUserId() but that doesn\'t seem to work here. The User.Identity doesnt have the GetUserId() method I am using Microsoft.AspNet.Identity 回答1: Until ASP.NET Core 1.0 RC1 : It's User.GetUserId() from System.Security.Claims namespace. Since ASP.NET Core 1.0 RC2 : You now have to use UserManager . You can create a method to get the current user : private Task<ApplicationUser> GetCurrentUserAsync() => _userManager.GetUserAsync(HttpContext.User

No executable found matching command “dotnet-ef”

﹥>﹥吖頭↗ 提交于 2019-11-26 05:28:47
问题 I\'m doing a project sample by using ASP.Net Core RC2 with Microsoft.EntityFramework.Core and SQLite. I\'ve followed this tutorial: https://damienbod.com/2015/08/30/asp-net-5-with-sqlite-and-entity-framework-7/ But, when I run this command : dotnet ef migrations add FirstMigration I got this error : No executable found matching command \"dotnet-ef\" Here is my project.json configuration: { \"dependencies\": { \"Microsoft.NETCore.App\": { \"version\": \"1.0.0-rc2-3002702\", \"type\": \