asp.net-core-1.0

asp.net core 1.0 web api use camelcase

只谈情不闲聊 提交于 2019-11-27 11:46:11
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 Brivvirs services .AddMvc() .AddJsonOptions(options => { options.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.DefaultContractResolver(); }); This keeps a JSON object's name the same as .NET class property. You can configure JSON behavior this way: public void ConfigureServices(IServiceCollection

How to add IHttpContextAccessor in the Startup class in the DI in ASP.NET Core 1.0?

南楼画角 提交于 2019-11-27 07:51:56
In ASP.NET Core RC 1 I used the following code to retrieve the value of context (full address of the page). Then I recorded this value in the configuration. public class Startup { public IConfigurationRoot Configuration { get; set; } private IHostingEnvironment CurrentEnvironment { get; set; } private IHttpContextAccessor HttpContextAccessor { get; set; } public Startup(IHostingEnvironment env, IHttpContextAccessor httpContextAccessor) { var builder = new ConfigurationBuilder() .SetBasePath(env.ContentRootPath) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) .AddJsonFile

ADO.NET entity data model (.edmx) in ASP.NET MVC core 1.0

南楼画角 提交于 2019-11-27 07:31:17
问题 I have couple of questions regarding how to use ADO.NET entity data model (.edmx) in ASP.NET MVC core 1.0 application- As we are migrating application from MVC 5 to MVC core 1.0, how do we migrate .edmx from MVC5 application developed in VS2013 to MVC core 1.0 new VS2015? How do I create new ADO.NET entity data model (.edmx) using Database First approach in MVC core 1.0 application in VS2015? [I have already tried creating POCO model and then use scaffold migration command, but want to

How to read connection string in .NET Core?

别等时光非礼了梦想. 提交于 2019-11-27 06:42:56
I want to read just a connection string from a configuration file and for this add a file with the name "appsettings.json" to my project and add this content on it: { "ConnectionStrings": { "DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=aspnet- WebApplica71d622;Trusted_Connection=True;MultipleActiveResultSets=true" }, "Logging": { "IncludeScopes": false, "LogLevel": { "Default": "Debug", "System": "Information", "Microsoft": "Information" } } } On ASP.NET I used this: var temp=ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString; Now how can I read

How to access node_modules folder from wwwroot in asp.net vnext project

不问归期 提交于 2019-11-27 06:41:11
问题 How can I access the node_modules folder which is not included in the visual studio solution file from the wwwroot where my index.html is put. That index.html file need to reference the npm installed packages like angular.js. But how? I do not want to copy the whole node_modules folder into wwwroot. Those are not the files to live there... I do not want to include the node_modules folder to the solution because that will slow down everything and hang up... It seems Frontend development

HttpContext.Authentication.SignOutAsync does not delete auth cookie

谁说胖子不能爱 提交于 2019-11-27 05:55:37
问题 According to ASP.NET Core documentation the method HttpContext.Authentication.SignOutAsync() must delete the authentication cookie as well. Signing out To sign out the current user, and delete their cookie (italics mine - A.C.) call the following inside your controller await HttpContext.Authentication.SignOutAsync("MyCookieMiddlewareInstance"); But it does not! Everything else seems okay, esp. auth scheme, because user gets signed-in correctly and the cookie .AspNetCore. is created. Any ideas

View scaffold templates in ASP.NET Core

纵然是瞬间 提交于 2019-11-27 03:49:42
问题 MVC 5 has the very handy feature when creating a view to be able to select a template for scaffolding out the view. This uses a T4 template file to generate a CSHTML file based on a specified type. Is there a way to do anything like this in ASP.Net Core 1.0? 回答1: You need to add references on Tools. But only for build time in project.json , add the following to the dependencies section: "Microsoft.VisualStudio.Web.CodeGeneration.Tools": { "version": "1.0.0-preview2-final", "type": "build" },

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

老子叫甜甜 提交于 2019-11-27 03:27:57
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/Product.cshtml To go further, if I had a controller like this: [Route("admin/marketing/[controller]")] public class

Is .NET Core Runtime backwards compatible with previous releases?

白昼怎懂夜的黑 提交于 2019-11-27 03:24:36
问题 If I've installed the latest version of the .NET Core Runtime (as of now, that's version 2.2.3): https://dotnet.microsoft.com/download/dotnet-core/2.2 Is that one installation backwards-compatible with previous releases of .NET Core? For example, will the above installation be compatible with an app which targets: netcoreapp1.0 netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 I realize that the .NET runtimes can be installed side-by-side. However, that does not answer my question. Is the one 2.2

Error handling (Sending ex.Message to the client)

ε祈祈猫儿з 提交于 2019-11-27 03:18:04
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 install the compat shim. Is there a new way of doing these things in Core 1.0? Here is something I have