asp.net-core-mvc

How to stream a video or a file considering request and response range headers?

我怕爱的太早我们不能终老 提交于 2019-12-03 18:32:23
问题 I am now using FileStreamResult and it works to stream a video, but can't seek it. It always starts again from the beginning. I was using ByteRangeStreamContent but it seems that it is not available anymore with dnxcore50 . So how to proceed ? Do i need to manually parse the request range headers and write a custom FileResult that sets the response Content-Range and the rest of the headers and writes the buffer range to the response body or is there something already implemented and i'm

HttpRuntime.Cache Equivalent for asp.net 5, MVC 6

情到浓时终转凉″ 提交于 2019-12-03 18:11:11
问题 So I've just moved from ASP.Net 4 to ASP.Net 5. Im at the moment trying to change a project so that it works in the new ASP.Net but of course there is going to be a load of errors. Does anyone know what the equivalent extension is for HttpRuntime as I cant seem to find it anywhere. I'm using to cache an object client side. HttpRuntime.Cache[Findqs.QuestionSetName] 'Findqs' is just a general object 回答1: You can an IMemoryCache implementation for caching data. There are different

ASP.NET Core 2 Unable to resolve service for type Microsoft EntityFrameworkCore DbContext

此生再无相见时 提交于 2019-12-03 17:26:33
问题 When I run my asp.net core 2 projects I get the following error message: InvalidOperationException: Unable to resolve service for type 'Microsoft.EntityFrameworkCore.DbContext' while attempting to activate 'ContosoUniversity.Service.Class.StudentService'. Here is my project structure: -- solution 'ContosoUniversity' ----- ContosoUniversity ----- ContosoUniversity.Model ----- ContosoUniversity.Service IEntityService (related code) : public interface IEntityService<T> : IService where T :

ServiceFilter and TypeFilter - what is the difference in injection those filters?

独自空忆成欢 提交于 2019-12-03 17:25:19
问题 ServiceFilter we must register in Startup.cs. TypeFilter is injected by Microsoft.Extensions.DependencyInjection.ObjectFactory, we don't need register that filter. So when we should use ServiceFilter and when TypeFilter ? 回答1: According to Pro ASP.NET Core MVC 2 book. Chapter 19: Filters , page # 615 When using the TypeFilter attribute, a new instance of the filter class is created for every request. This is the same behavior as applying a filter directly as an attribute, except that the

Force locale with Asp.Net Core

一个人想着一个人 提交于 2019-12-03 17:22:46
I'm having some odd issues with a web application written using Asp.Net Core 1.1, using the full .Net Framework v4.6.2. I want to force the application to use a swedish locale (sv-SE). This is working just fine on the development machine (of course...) but not on the server where it's supposed to run (running Windows Server 2012r2). I've tried the following: 1) Putting "SiteLocale": "sv-SE" in the appsettings.json file. 2) Putting the following in the web.config <configuration> <system.web> <globalization culture="sv-SE" uiCulture="sv-SE" /> </system.web> ... </configuration 3) In program.cs

ASP.NET Core configuration reloadOnChange with IOptionsSnapshot still not responsive

给你一囗甜甜゛ 提交于 2019-12-03 17:19:56
问题 I'm using ASP.NET Core 2.0 and I have configuration code like this in the Main method: public static void Main(string[] args) { var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"); var configuration = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) .AddJsonFile($"appsettings.{environment ?? "Production"}.json", optional: true, reloadOnChange: true)

Logging within Program.cs

感情迁移 提交于 2019-12-03 16:58:36
问题 Is it possible to get an ILogger inside Program.cs Main method? I want to pass it on to a service that's created inside that method. I've only found this on SO How do I write logs from within Startup.cs , but that's logging within Startup.cs. 回答1: Accidentally stumbled upon the answer after googling a bit more. using System; using Microsoft.Extensions.Logging; namespace ConsoleApplication { public class Program { public static void Main(string[] args) { var logFactory = new LoggerFactory()

Injecting DbContext into service layer

拜拜、爱过 提交于 2019-12-03 16:56:19
问题 How am I supposed to inject my MyDbContext into my database service layer MyService ? Startup.cs public void ConfigureServices(IServiceCollection services) { services.AddDbContext<MyDbContext>(options => options.UseSqlServer(Configuration["ConnectionStrings:DefaultConnection"])); services.AddMvc(); } MyDbContext.cs public partial class MyDbContext : DbContext { public virtual DbSet<User> User { get; set; } public MyDbContext(DbContextOptions<MyDbContext> options) :base(options) { } }

Does a Stream get Disposed when returning a File from an Action? [duplicate]

ぐ巨炮叔叔 提交于 2019-12-03 16:51:55
问题 This question already has answers here : Does FileStreamResult close Stream? (1 answer) How do I dispose my filestream when implementing a file download in ASP.NET? (2 answers) Closed 2 years ago . I'm writing a string to a MemoryStream I need to return the stream to the Controller Action so I can send it off as a file for download. Normally, I wrap the Stream in a using statement, but, in this case, I need to return it. Does it still get Disposed after I return it? Or do I need to dispose it

Not able to redirect to action when using TempData in Asp.Net Core

此生再无相见时 提交于 2019-12-03 16:24:50
I am trying to achieve a simple thing in Asp.Net Core. This would have been no big deal in Asp.Net Mvc. I have an action method like this public async Task<IActionResult> Create([Bind("Id,FirstName,LastName,Email,PhoneNo")] Customer customer) { if (ModelState.IsValid) { _context.Add(customer); await _context.SaveChangesAsync(); TempData["CustomerDetails"] = customer; return RedirectToAction("Registered"); } return View(customer); } public IActionResult Registered() { Customer customer = (Customer)TempData["CustomerDetails"]; return View(customer); } At first I assumed TempData works by default