asp.net-core-mvc

ASP.NET Core MVC, Get file from database, and render as image

て烟熏妆下的殇ゞ 提交于 2019-12-19 03:23:16
问题 I have image data being stored in a SQL table with a field type of varbinary(max) I also store the image content type. Using Microsoft ASP.NET Core MVC and Dapper, I am trying to get the file back from the database and render it as an image. This is my FileModel : using System; namespace Brand.Models { public class FileModel { public Guid ID { get; set; } public string FileName { get; set; } public string FileType { get; set; } public byte[] FileData { get; set; } public int FileLength { get;

How to manage ASP.NET Core bundleconfig.json for multiple environments?

孤人 提交于 2019-12-19 02:47:36
问题 What's the best practice for using the ASP.NET Core bundleconfig.json with development versus production environments? The prior bundler (BundleCollection) would pay attention to the DEBUG compiler directive and not minify the list of scripts when you're debugging. It appears as though the new paradigm is to have <environment> tags in the HTML templates that test for the ASPNETCORE_ENVIRONMENT value. Though I don't see a way of incorporating that environment variable into the bundleconfig

ASP.NET Core DependencyResolver

浪子不回头ぞ 提交于 2019-12-18 19:15:10
问题 In ASP.NET MVC 5 is possible to obtain some dependency through DependencyResolver.Current.GetService<T>() . Is there something similar in ASP.NET Core? 回答1: Yes, there is. In ASP.NET Core 1.0.0, the services available within a request from HttpContext are exposed through the RequestServices collection [1] : this.HttpContext.RequestServices You can use the GetService method to retrieve the dependencies by specifying the type of the dependency: this.HttpContext.RequestServices.GetService(typeof

Is there any difference between the Ok() method new ObjectResult()?

試著忘記壹切 提交于 2019-12-18 18:37:53
问题 Scenario: implementing a standard REST API / GET method on a .net core controller. The documentation states that OkObjectResult is an ObjectResult with status 200. This is available through the Ok(myResult) method inherited from ControllerBase. I assume this is a convenience method. However, the tutorial is not using this approach - it instead returns new ObjectResult(myResult) which will default to status 200. Is there any difference between these two approaches? 回答1: Technically there is no

UseSqlServer method missing MVC 6

对着背影说爱祢 提交于 2019-12-18 18:36:35
问题 I am trying to implement Entity Framework 7 in MVC 6, and on this page here it says to do services.AddEntityFramework() .AddSqlServer() .AddDbContext<MusicStoreContext>(options => options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"])); But for me, the UseSqlServer method isnt visible? Anyone know how to make it visible? Or is this an old way of configuring entity framework? My startup.cs file looks like this using FluentValidation; using Microsoft.AspNet.Builder;

Assigning multiple routes to the same controller or action in ASP MVC 6

眉间皱痕 提交于 2019-12-18 18:36:03
问题 Question: Is there any way to assign two different routes (with parameters) to the same controller in an ASP.NET MVC 6 application? I Tried: I tried using multiple route attributes to the controller class and also to the individual actions, did not work. Notes: I am using ASP.NET Core 1.0 RC1. The reason I want to do this is, I want the api to be compatible with the older version of our mobile app which use the old URL. Example: [Produces("application/json")] [Route("api/v2/Log")] /// The old

Assigning multiple routes to the same controller or action in ASP MVC 6

只谈情不闲聊 提交于 2019-12-18 18:35:24
问题 Question: Is there any way to assign two different routes (with parameters) to the same controller in an ASP.NET MVC 6 application? I Tried: I tried using multiple route attributes to the controller class and also to the individual actions, did not work. Notes: I am using ASP.NET Core 1.0 RC1. The reason I want to do this is, I want the api to be compatible with the older version of our mobile app which use the old URL. Example: [Produces("application/json")] [Route("api/v2/Log")] /// The old

Adding images to ASP.net core

感情迁移 提交于 2019-12-18 17:37:29
问题 I wanted to add an image as part of the model class and display it on the index view. I'm having problems either classifying the image as a byte[] or iFormFile. This is what I'm trying to achieve Create a page to insert a list of employees In the index page, able to list the employees and see their images as well. Here's the model. Employee.cs using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Threading.Tasks; using

Adding images to ASP.net core

扶醉桌前 提交于 2019-12-18 17:37:09
问题 I wanted to add an image as part of the model class and display it on the index view. I'm having problems either classifying the image as a byte[] or iFormFile. This is what I'm trying to achieve Create a page to insert a list of employees In the index page, able to list the employees and see their images as well. Here's the model. Employee.cs using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Threading.Tasks; using

ASP.NET Core 2 default route having areas

北城余情 提交于 2019-12-18 17:26:26
问题 cI went through various posts regarding the Areas routing but still I am not able to resolve my issue. I would like to split my application in the way that there are two routes. /Areas/Panel /Areas/Website Inside each area there is HomeController and appropriate methods that correspond to actions. I would like that whenever user lands to any level 1 route i.e.: /home /contact /about/company etc. is directed to /Areas/Website/{controller}/{action} and alternatively for /panel /panel/home