asp.net-core-1.0

Access configuration through dependency injection in .NET Core console application

♀尐吖头ヾ 提交于 2019-12-10 21:19:43
问题 How do I properly Activate a configuration that was added using the ServiceCollection.Configure function ? public static void Main(args[] args) { serviceCollection = new ServiceCollection(); serviceCollection .Configure<MyOptions>(Configuration.GetSection("options")); Services = serviceCollection.BuildServiceProvider(); ActivatorUtilities.CreateInstance<MyOptions>(Services); ActivatorUtilities.CreateInstance<SomeClassThatNeedsoptions>(Services); } public SomeClassThatNeedsoptions(IOptions

IApplicationBuilder does not contain a definition for UseWebApi

烂漫一生 提交于 2019-12-10 20:09:39
问题 The VS 2015 Update 3 is out and I have started playing with it. But I hit a problem soon after. The IApplicationBuilder interface does not appear to have a definition for the UseWebApi extension method, but IAppBuilder does. In effect, I want to register my Web Api with the OWIN pipeline. Am I missing something? 回答1: There is no need for the IApplicationBuilder interface to have a definition for the UseWebApi extension method. In IAppBuilder , it was used to register a Web Api with OWIN. But

How to send data to an ASP.NET Controller with Angular2

拥有回忆 提交于 2019-12-10 20:04:03
问题 I have a controller that has a Create action. Its purpose is to receive a name and data from file form, and IndexViewModel return IEnumerable<File> files. public class HomeController : Controller { static List<Models.File> files = new List<Models.File>(); public HomeController() { } [HttpGet] public IActionResult Index() => View(new IndexViewModel { Files = files }); [HttpGet] public IActionResult Create() => View(); [HttpPost] public IActionResult Create(IFormFile file) { var filename =

ASP.NET Core 1 Modular (Plugin) Architecture? [closed]

会有一股神秘感。 提交于 2019-12-10 19:21:31
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 3 years ago . I'm designing an architecture for a web application product using ASP.NET Core 1. I want the architecture to be modular and plugin. I want each module to be separated from the main application, and can be easily toggled ON and OFF. I found this open source framework ExtCore

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

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

What does it mean for an entity type to be in “shadow state”?

試著忘記壹切 提交于 2019-12-10 14:24:07
问题 In my ASP.NET Core 1.0, MVC6, EF7 web application, I'm adding a migration that adds a new related table (& corresponding model). I have the following model snapshot: [DbContext(typeof(ApplicationDbContext))] partial class ApplicationDbContextModelSnapshot : ModelSnapshot { protected override void BuildModel(ModelBuilder modelBuilder) { modelBuilder .HasAnnotation("ProductVersion", "7.0.0-rc1-16348") .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy

Localization in separate project Asp.net Core MVC

孤人 提交于 2019-12-10 12:55:51
问题 I just upgraded to Rc2 and what used to work no longer does. I have a couple of resx files in a separate project and I use a custom class to access the data. Now I get the following error when running it: MissingManifestResourceException: Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "GarageWeb.Core.CoreResources.resources" was correctly embedded or linked into assembly "GarageWeb.Core" at compile time, or that all the satellite

Cannot add Scaffold > MVC Controller with views, using Entity Framework in Asp.NET Core

我怕爱的太早我们不能终老 提交于 2019-12-10 12:15:35
问题 When I try to add Controller using build-in generator I get following error message: Where "Brand" is a model class and "ApplicationDbContext" is my data context class. I never encoutered error like this before. It does not occur all the time (2 success vs 30-40 attempts without changing single line of code). I was able to create Controller for same class minutes ago, but it's really annoying when you try to add something new and try more than 10 times with no results. Of course, I could

Duplicate type name within an assembly in Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware

て烟熏妆下的殇ゞ 提交于 2019-12-10 12:12:54
问题 I have .NET Core 1.1 API and i am handling the error in startup.cs as below. I am using Serilog public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IApplicationLifetime appLifetime, IRequestContext requestContext) { loggerFactory.AddSerilog(); // Ensure any buffered events are sent at shutdown appLifetime.ApplicationStopped.Register(Log.CloseAndFlush); var logger = loggerFactory.CreateLogger<Startup>(); app.UseExceptionHandler( options => {