asp.net-core-mvc

Why is IFormFile showing null, and how do I fix it?

ぃ、小莉子 提交于 2019-12-18 11:17:30
问题 I am using ASP.NET 5, MVC 6 in VS 2015. I am making a web application. On my form I have: <form method="post" enctype="multipart/form-data"> <div id="uploadSection" > <label >Select files for upload</label> <input type="file" id="fileSelect" name="fileSelect" multiple /> </div> <div> <input type="submit" id="thisbutton" value="button" /> </div> </form> in my controller: [HttpPost] public async Task<IActionResult> FileForm(FileViewModel vm, IFormFile file) { if (ModelState.IsValid) { /

run .net core application in development from the command line

久未见 提交于 2019-12-18 09:29:38
问题 I know I can configure some settings in Visual Studio or Visual Studio Code to launch my asp .net core application in development mode. But I've had a horrible experience with all the build tools, and so far running from the command line is the only one working for me. The big problem I have with the command line is getting it to run in Development mode. If I understand, this can only be done by typing set ASPNETCORE_ENVIRONMENT=Development before dotnet watch run or by setting system wide

Route application root to /swagger

一曲冷凌霜 提交于 2019-12-18 08:55:43
问题 What is the correct way to redirect request from www.mysite.com to www.mysite.com/swagger? I setup an index controller Decorated with Route("") and it works but seems like a Kludge. I assume there should be a way to specify it in the MVC routing in Startup.cs, I just can't figure it out. // kludge code, how do I do this in app.UseMvc(route => route.MapRoute... [ApiExplorerSettings(IgnoreApi = true)] [Route("")] public class IndexController : Controller { public ActionResult Index() { return

Getting hold of raw POST data when using [FromBody]

戏子无情 提交于 2019-12-18 08:21:31
问题 I have a controller running on ASP.NET Core 1.0 RC2 and I'd like to dump the raw POST data out to telemetry as ApplicationInsights doesn't do this for you. My code looks like this [HttpPost] [Produces("application/json")] public IActionResult Post([FromBody] RequestClass RequestData) { var stream = this.HttpContext.Request.Body; stream.Position = 0; using (var reader = new StreamReader(stream)) { string body = reader.ReadToEnd(); Telemetry.TrackTrace(body, Microsoft.ApplicationInsights

Exception-Handling Middleware and Page

巧了我就是萌 提交于 2019-12-18 07:52:33
问题 I'm new to the concept of middleware, and am currently struggling with the proper way to handle exceptions in my MVC Core project. What I want to happen is for the Exception to be caught, logged, and then send the user to a friendly error page with a message. At first, I was trying to manage all of these within the middleware, but realized I probably wasn't doing it correctly. So if I want this flow to happen, should I use both my Exception-logging middleware AND the app.UseExceptionHandler("

Microsoft.AspNetCore.Antiforgery was not found

蹲街弑〆低调 提交于 2019-12-18 07:32:10
问题 I'm deploying a asp.net core 2.0 website to IIS 10. I've made sure that my app is using the correct configuration for ISS in the program.settings file. public class Program { public static void Main(string[] args) { BuildWebHost(args).Run(); } public static IWebHost BuildWebHost(string[] args) => WebHost.CreateDefaultBuilder(args) .UseKestrel() .UseContentRoot(Directory.GetCurrentDirectory()) .UseIISIntegration() .UseStartup<Startup>() .Build(); } And in my startup.cs file: public void

Installing KVM Broke Current asp.net vnext Web Project

℡╲_俬逩灬. 提交于 2019-12-18 07:11:30
问题 I installed the KVM using command line and my web project in VS2015 preview broke not compiling, but if add a new web project all works fine, how do uninstall the KVM so I can get my old project working. In this video Scott mention the issue but no solution, please see link, the video mention the issue at the 8:00 minute video 1: http://channel9.msdn.com/Series/Whats-New-with-ASPNET-5/05 I change the to use the default alias but that did not work NuGet Settings 回答1: I believe your versions

Unable to write data to the transport. Vs2017 ASP.net core Scaffolding ( MSSQL WINDOW 10)

若如初见. 提交于 2019-12-18 07:06:35
问题 I am trying to create a controller by scaffolding. But I receive this error There was an error running the selected code generator. Unable to write data to the transport.An established connection was aborted by software in your host machine I am using ASP.NET CORE, Visual studio 2017, SqlServer, Window 10 For days now I am tring to solve this problem with no lucky Can anyone help? 回答1: After a long suffering I was able to identify the problem Firewall/antivirus or any network filtering app

Asp net core rc2. Abstract class model binding

折月煮酒 提交于 2019-12-18 06:16:12
问题 In the RC1 I use the following code for abstract classes or interfaces binding: public class MessageModelBinder : IModelBinder { public Task<ModelBindingResult> BindModelAsync(ModelBindingContext bindingContext) { if(bindingContext.ModelType == typeof(ICommand)) { var msgTypeResult = bindingContext.ValueProvider.GetValue("messageType"); if(msgTypeResult == ValueProviderResult.None) { return ModelBindingResult.FailedAsync(bindingContext.ModelName); } var type = Assembly.GetAssembly(typeof

Failed to make the following project runnable (Object reference not set to an instance of an object.)

纵然是瞬间 提交于 2019-12-18 05:44:43
问题 When I create default web project in Visual Studio 2015 (Update 3) with installed .NET Core 1.0 SDK and Tooling (preview 2) and restart the Visual Studio after reverting local source control changes I am getting the following compilation error : Failed to make the following project runnable: MyDefaultWebProject (.NETCoreApp,Version=v1.0) reason: Object reference not set to an instance of an object. According to Visual Studio the error is located in C:\Program Files (x86)\MSBuild\Microsoft