asp.net-core-mvc

WebApiCompatShim - how to configure for a REST api with MVC 6

十年热恋 提交于 2019-12-20 03:35:26
问题 I was having a look at this link that shows how to migrate from Web API 2 to MVC 6. I am trying to have Action methods in my controllers with the HttpRequestMessage bound. This works in Web Api 2. [Route("", Name = "AddTaskRoute")] [HttpPost] public Task AddTask(HttpRequestMessage requestMessage, [FromBody]NewTask newTask) { var task = _addTaskMaintenanceProcessor.AddTask(newTask); return task; } and the requestMessage contains the details about the Http request such as headers, verb, etc. I

Post using HttpClient & Read HttpResponseMessage status

隐身守侯 提交于 2019-12-20 03:18:18
问题 I am posting to an API using HttpClient and getting back the HttpResponseMessage . I am reading the status code from the reply but I it's always 200 Posting: var json = JsonConvert.SerializeObject(loginDto); var stringContent = new StringContent(json, Encoding.UTF8, "application/json"); var client = new HttpClient(); var response = await client.PostAsync("http://localhost:57770/api/Account/Login", stringContent); I am replying from API the HttpResponseMessage : return new HttpResponseMessage

How to fix overlapping Google Chart legend

谁说我不能喝 提交于 2019-12-20 02:59:22
问题 This has been something I've been working on for hours now and I can't seem to find a solution that works. I have a page (ASP.NET Core) that has bootstrap tabs on it. Each tab displays a different chart. I've read various answers and tried so many different things from this and other sites but I'm sure what I'm doing wrong. This is a proof of concept page I'm making and from what I understand I need to stall the loading of the chart until the nav-tab is selected. That is what I am unsure of

Cookies in ASP.NET Core rc2

老子叫甜甜 提交于 2019-12-20 02:50:06
问题 Can someone pls explain how to store and get cookies in an ASP.NET Core rc2 application? I can only find outdated information about the old HttpContext.Response.Cookies.Get and Add methods, neither of which still exist in Core. Also, the HttpCookie class doesn't seem to exist either. What is the new cookie class and how can I get and add one? (Note: I am not specifically taking about authentication cookies, just general data cookies) 回答1: For getting request cookie value: HttpContext.Request

Current URL in ASPCore Middleware?

五迷三道 提交于 2019-12-20 02:47:33
问题 Is there a way I can access the current Requested URL in ASPCore 2.0 Middleware? Is there something I can Inject? 回答1: HttpContext object will be passed to the Invoke method of your middleware. You can access the Request property on that. You can use the GetDisplayUrl extension method or GetEncodedUrl extension method. public Task Invoke(HttpContext context) { var url1 =context.Request.GetDisplayUrl(); var url2 = context.Request.GetEncodedUrl(); // Call the next delegate/middleware in the

How do I read a local file in my ASP.NET Core project

a 夏天 提交于 2019-12-20 02:41:44
问题 If I want to read a local file from my project, given a relative path from the project directory, how could I achieve this? 回答1: You can get the ApplicationBasePath from PlatformServices.ApplicationEnvironment . This will make it possible to resolve non-absolute paths relative to your application base path. 回答2: Now that .Net Core has RTM-ed you need to use IHostingEnvironment instead. It exposes WebRootPath and ContentRootPath 来源: https://stackoverflow.com/questions/35877583/how-do-i-read-a

Reloading Options with reloadOnChange in ASP.NET Core

别来无恙 提交于 2019-12-20 02:27:40
问题 In my ASP.NET Core application I bind the appsettings.json to a strongly typed class AppSettings . public Startup(IHostingEnvironment environment) { var builder = new ConfigurationBuilder() .SetBasePath(environment.ContentRootPath) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) .AddJsonFile($"appsettings.{environment.EnvironmentName}.json", optional: true, reloadOnChange: true) .AddEnvironmentVariables(); Configuration = builder.Build(); } public void ConfigureServices

There is no argument given that corresponds to the required formal parameter 'options'

不羁岁月 提交于 2019-12-20 01:34:32
问题 I'm working on my first application in .Net Core. I'm getting this build error for some reason: Error CS7036 There is no argument given that corresponds to the required formal parameter 'options' of 'LakeViewContext.LakeViewContext(DbContextOptions<LakeViewContext>)' LakeView I wasn't able to find a solution through Google Search or MS documentation. My Context class: using LakeView.Models; using Microsoft.EntityFrameworkCore; namespace LakeView { public class LakeViewContext : DbContext {

Razor engine cant find view

蓝咒 提交于 2019-12-19 18:28:07
问题 Im trying to render a html from a view without using a web request. I need the HTML as a string, internally, i do not wish to serve it. The viewEngine.FindView() returns a viewEnineResult that shows no view was found. It shows to search locations where it looked they look like this: /Views//PDFOperationsReportView.cshtml /Views/Shared/PDFOperationsReportView.cshtml (Observe the double forward slash in the first line) File structure (I placed it into a HTML snippet cause i couldnt manage to

How to update appsettings.json based on publish profile using .NET Core?

余生颓废 提交于 2019-12-19 17:45:40
问题 I'm currently making the switch from .NET Framework to .NET Core. In the past, all of my application settings were in the Web.config file. When I added a new publish profile, I could right click and select 'Add Config Transform' which would generate a nested Web.{Profile}.config file under Web.config where I could set application settings that were specific to the respective profile. Now, in .NET Core, I want to achieve the same effect using an appsettings.json file instead of Web.config file