asp.net-core-mvc

ASP.NET 5 on Visual Studio 2015 addMvc method not found

我是研究僧i 提交于 2019-12-10 17:26:52
问题 I am following this tutorial: http://www.asp.net/vnext/overview/aspnet-vnext/create-a-web-api-with-mvc-6 to setup a web api and I have not made it very far. Once I added the line: services.addMvc(); I got an exception saying this method is not found. I searched online and found a separate question/answer here: http://forums.asp.net/t/2026087.aspx but that did not help. My startup.cs looks like this: public void ConfigureServices(IServiceCollection services) { services.AddMvc(); } public void

How to return large Json in Asp.Net Core

混江龙づ霸主 提交于 2019-12-10 17:21:24
问题 In classic asp.net in order to return large json data i enable it web.config <system.web.extensions> <scripting> <webServices> <jsonSerialization maxJsonLength="2147483644"/> </webServices> </scripting> </system.web.extensions> and then also set the max length in action method public ActionResult GetData() { var data = _service.GetData(); var json = Json(data); json.MaxJsonLength = Int32.MaxValue; return json; } what is equivalent in ASP.NET core? In asp.net core I don't see JsonResult has

Using sessions in ASP.NET 5 (MVC 6)

半城伤御伤魂 提交于 2019-12-10 17:18:46
问题 I'm having trouble getting sessions to work in my MVC 6 project. I read a great article about this , but I cant get app.UseInMemorySession(); to work in my Startup.cs as described. I added "Microsoft.AspNet.Session": "1.0.0-beta6" to the dependencies part of my project.json and modified my Startup.cs as follows: My Configuration part looks like this: public void ConfigureServices(IServiceCollection services) { // Add MVC services to the services container. services.AddMvc(); services

Asp.Net Core Web app: Global exception handling using IExceptionFilter vs custom middleware

限于喜欢 提交于 2019-12-10 17:16:47
问题 Asp.Net Core supports two ways to do global exception handling for a Web Application, implementing IExceptionFilter or by creating custom middleware. Is there any advantage of one over the other? Most references I see are for creating custom middleware. 回答1: The ASP.NET Core docs explains the main differences between these two approaches. It states that exception filters: Handle unhandled exceptions that occur in Razor Page or controller creation, model binding, action filters, or action

How to enable property injection on controllers using Autofac and ASP.NET Core?

浪尽此生 提交于 2019-12-10 17:14:43
问题 There doesn't really seem to be an easy way to make sure the controllers have property injection. A way around it would be to register all controllers individually, which seems to defeat the purpose a bit. The [FromServices] attribute is removed and they specifically mention it should be up to the individual IoC containers to make sure this happens. Am I missing something glaringly obvious? Looked for all available extension methods but didn't find anything, same for issues and the discussion

How to configure ASP.NET Core to handle circular references without breaking the body's response?

感情迁移 提交于 2019-12-10 17:13:37
问题 I have this ASP.NET Core 2.0 MVC Controller: [Route("api/[controller]")] public class SampleDataController : Controller { [HttpGet("[action]")] public Example Demo() { return new Example("test"); } public class Example { public Example(string name) { Name = name; } public string Name { get; } public IEnumerable<Example> Demos { get { yield return this; } } } } When querying /api/SampleData/Demo , I get as response body: {"name":"test","demos":[ ...which is obviously very broken JSON-like

Replace value in cookie ASP.NET Core 1.0

冷暖自知 提交于 2019-12-10 16:45:05
问题 I'm using the cookie middleware in ASP.NET Core 1.0 without ASP.NET Identity - as described in this article: https://docs.asp.net/en/latest/security/authentication/cookie.html When a user makes certain changes to his/her profile, I need to change some values in the cookie. In such scenarios, this article tells me to call context.ReplacePrincipal() and set the context.ShouldRenew flag to true How exactly do I do that? I think the article is referring to HttpContext. I don't see a

How to push configuration values from Asp.Net Core MVC 2.0 config file to React TypeScript client script?

前提是你 提交于 2019-12-10 16:25:40
问题 I have an application on ASP.NET MVC Core 2.0 using React Template . I have propertie in config file on server side - SiteURL . I need to push it to client TypeScript , and don`t understand how can I make it? I tried to push them throw Home/Index file by placing in the last script SiteProps.SiteURL= "http://mysiteurl.org" and on client I make export var SiteProps: { SiteURL: string } = {SiteURL: ""}; and import this file on boot But testing this property on console I see Uncaught

IIS Express command line ASP.NET MVC 6 beta 8

二次信任 提交于 2019-12-10 16:04:26
问题 I created an ASP.NET MVC 6 beta 8 application and when I click debug in Visual Studio 2015 I can see IIS Express and the site works properly. But if I try and launch IIS Express from the command line pointing to the right applicationHost.config file I get and error, does something else need to be added? C:\Program Files (x86)\IIS Express>iisexpress /config:D:\Programming\Projects\WebApplication1.vs\config\applicationHost.config /siteid:3 HTTP Error 502.3 - Bad Gateway There was a connection

asp.net core and including shared content files

梦想的初衷 提交于 2019-12-10 16:02:00
问题 I have a Shared Project project which contains some content files like JSON, etc. I have a number of ASP.Net core projects and I want to include/share some of these JSON files. Very simple with the "Link to File" option in VS but it's not available in ASP.Net core projects. I've tried playing with the buildOptions/copyToOutput as follows but this does not seem to be working and no error or warning logged in the build process. "copyToOutput": { "include": [ "../Common.Includes/mysettings*.json