asp.net-core-1.0

Form submit resulting in “InvalidDataException: Form value count limit 1024 exceeded.”

≡放荡痞女 提交于 2019-11-30 07:59:43
I have created an mvc site and I'm posting a large amount of json form data ( Content-Type:application/x-www-form-urlencoded ) back to the mvc controller. When I do this, I receive a 500 response that states: "InvalidDataException: Form value count limit 1024 exceeded." In previous versions of aspnet, you would add the following to the web.config to increase the limit: <appSettings> <add key="aspnet:MaxHttpCollectionKeys" value="5000" /> <add key="aspnet:MaxJsonDeserializerMembers" value="5000" /> </appSettings> When I put these values in the web.config, I do not see any change, so I'm

Entity Framework Core 1.0 unit of work with Asp.Net Core middleware or Mvc filter

て烟熏妆下的殇ゞ 提交于 2019-11-30 06:46:42
问题 I am using EF Core 1.0 (previously known ad EF7) and ASP.NET Core 1.0 (previously known as ASP.NET 5) for a RESTful API. I'd like to have some unit of work scoped to an http request in such a way that when responding to the HTTP request either ALL the changes made to the DbContext will be saved onto the database, or none will be saved (if there was some exception, for example). In the past I have used WebAPI2 for this purpose with NHibernate by using an Action filter where I begin the

How to keep using ModelState with RedirectToAction in ASP.NET MVC 6?

半城伤御伤魂 提交于 2019-11-30 05:44:34
问题 I have a method to remove the object. Removal does not own view, and is a "Delete" button in the "EditReport". Upon successful removal of a redirect on "Report". [HttpPost] [Route("{reportId:int}")] [ValidateAntiForgeryToken] public IActionResult DeleteReport(int reportId) { var success = _reportService.DeleteReportControl(reportId); if (success == false) { ModelState.AddModelError("Error", "Messages"); return RedirectToAction("EditReport"); } ModelState.AddModelError("OK", "Messages");

How to save IFormFile to disk?

∥☆過路亽.° 提交于 2019-11-30 05:38:48
I'm trying to save a file on disk using this piece of code . IHostingEnvironment _hostingEnvironment; public ProfileController(IHostingEnvironment hostingEnvironment) { _hostingEnvironment = hostingEnvironment; } [HttpPost] public async Task<IActionResult> Upload(IList<IFormFile> files) { foreach (var file in files) { var fileName = ContentDispositionHeaderValue .Parse(file.ContentDisposition) .FileName .Trim('"'); var filePath = _hostingEnvironment.WebRootPath + "\\wwwroot\\" + fileName; await file.SaveAsAsync(filePath); } return View(); } I was able to replace IApplicationEnvironment with

Right way to work with RSS in ASP.NET Core 1.0 RC2

倾然丶 夕夏残阳落幕 提交于 2019-11-30 04:57:39
What is the right/best way to get data from an RSS feed using ASP.Net Core 1.0 (RC2) in C#. I want to work with the data in the RSS feed from my Wordpress blog which is https://blogs.msdn.microsoft.com/martinkearn/feed/ I know that in ASP.net 4.x, you'd use RssReader or SyndicationFeed but I cannot find an equivalent for ASP.net core. This is as far as I have got which returns the raw feed but I do not know how to extract the data from it. I want to enumerate the items and get the title and description from each one var feedUrl = "https://blogs.msdn.microsoft.com/martinkearn/feed/"; using (var

How to use SqlServer.Types / spatial types within ASP.NET Core 1.0 application

偶尔善良 提交于 2019-11-30 03:55:01
One of our class libraries uses the Microsoft spatial types like DbGeography. When running our application on a clean machine without older versions of SQL Server and Visual Studio, we get this exception: Spatial types and functions are not available for this provider because the assembly 'Microsoft.SqlServer.Types' version 10 or higher could not be found. The solution is apparently to install this nuget package: Install-Package Microsoft.SqlServer.Types After installing, the nuget package gives instructions on how to reference the DLLs from each project type: To deploy an application that

RemoteIpAddress is always null

谁说我不能喝 提交于 2019-11-30 03:51:55
问题 var test1 = HttpContext.Features.Get<IHttpConnectionFeature>(); var test2 = HttpContext.Connection.RemoteIpAddress; When running the application locally on IISExpress , these two lines correctly return the value 0:0:1 . When I publish the application on IIS 7.5 (which is running on a VM). RemoteIpAddress is always null I am using ASP.Net 5 RC 1 . How can I get the client's IP address in an ASP.NET 5 application ? I tried the solutions in the following questions, however I have the problem

The dependency Microsoft.Composition 1.0.27 does not support framework .NETCoreApp,Version=v1.1

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-30 02:58:32
问题 When I upgrade framework section to: "frameworks": { "netcoreapp1.1": { "dependencies": { }, "imports": "dnxcore50" } } I am getting error The dependency Microsoft.Composition 1.0.27 does not support framework .NETCoreApp,Version=v1.1. With "Microsoft.VisualStudio.Web.CodeGeneration.Tools" : underlined 回答1: Microsoft.Composition supports .NET Framework 4.5, Windows 8 and WindowsPhone 8.1 among other targets, this means it should work. But it doesn't target netstandard1.x specifically neither

Custom 401 and 403 response model with UseJwtBearerAuthentication middleware

杀马特。学长 韩版系。学妹 提交于 2019-11-30 02:43:09
问题 I want to respond with a JSON response model when a 401 and 403 occur. For example: HTTP 401 { "message": "Authentication failed. The request must include a valid and non-expired bearer token in the Authorization header." } I am using middleware (as suggested in this answer) to intercept 404s and it works great, but it is not the case with 401 or 403s. Here is the middleware: app.Use(async (context, next) => { await next(); if (context.Response.StatusCode == 401) { context.Response

How to get “Manage User Secrets” in a .NET Core console-application?

安稳与你 提交于 2019-11-30 02:42:28
When I create a new ASP .NET Core Web -Application, I can right-click the project in Visual Studio, and I see a context-menu entry called "Manage User Secrets". When I create a new .NET Core Console -Application, I don't see this context-menu entry. However, a "Web"-Application shows as "console" application in the project settings. Is there any way I can get this context-menu entry in a console-application ? "Manage user secrets" from a right click is only available in web projects. There is a slightly different process for console applications It requires manually typing the required