asp.net-core-2.0

EF Core Fluent API Configuration Prevents TPC Inheritance

南楼画角 提交于 2019-12-13 02:35:02
问题 I have models which inherit from each other, but I am struggling to get the fluent api configuration to behave as I want it to. Let's say I have a base class which defines some core properties public class Entity { public int Id { get; set; } public string Title { get; set }; } And a subclass for Book public class Book : Entity { public int Edition { get; set; } } This way I can have books, magazines, pamphlets, comics, speeches etc, all inheriting from my Entity, and not have to define the

Database connection not created in IdentityDbContext

梦想与她 提交于 2019-12-13 02:04:04
问题 I'm trying to authentication Asp.Net Core 2 Web API with Asp.Net Identity 2. Here's my code for the AuthController and the databasecontext: public AuthController(UserManager<ApiUser> userManager, SignInManager<ApiUser> signInManager, RoleManager<ApiRole> roleManager , IPasswordHasher<ApiUser> passwordHasher, IConfiguration configurationRoot, ILogger<AuthController> logger) { _userManager = userManager; _signInManager = signInManager; _roleManager = roleManager; _logger = logger;

ASP.NET Core 2 : Ajax calls to API with [Authorize] fail the preflight request

拥有回忆 提交于 2019-12-12 22:21:17
问题 I have an API controller with the [Authorize] attribute to ensure all calls are made by properly logged-in users (via OpenIdConnect, targeting Azure AD) . When I load the page that makes the Ajax calls, the API responds properly. However, after a certain amount of time, the user has to be reauthorized, and thus a call to https://login.microsoftonline.com/ is made by the ASP.NET Core framework to reauth the user. That calls fails with the following error: Failed to load https://login

T4 Template Could not load file or assembly 'System.Runtime, Version = 4.2.0.0'

我怕爱的太早我们不能终老 提交于 2019-12-12 20:01:29
问题 So I have a T4 Template I'm trying to run at design-time, but it keeps giving me the following error. Running transformation: System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. File name: 'System.Runtime, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' My Visual Studios solution has 10 projects contained

How to retrieve a service in razor pages with dependency injection

孤街醉人 提交于 2019-12-12 19:17:17
问题 In ASP.NET Core 2 application I set up some services: public void ConfigureServices(IServiceCollection services) { services.AddDbContext<MyContext>(options => options.UseSqlServer(Configuration.GetConnectionString("MyContext"))); services.AddHangfire(options => options.UseSqlServerStorage(Configuration.GetConnectionString("MyContext"))); services.AddOptions(); services.Configure<MySettings>(options => Configuration.GetSection("MySettings").Bind(options)); services.AddMvc()

Accessing MVC DI Service inside other services

泄露秘密 提交于 2019-12-12 17:05:38
问题 I am constructing a HealthAPI Class Library Which provides a list of statistics to our HealthMonitor Service. I have successfully got this working, The Middleware is recording Service boot time and recording response times, our health monitor is able to parse these values via a call to a our StatusController which has a number of actions returning IActionResult JSON responses. We intend to reuse this over all of our services so have opted to keep the API controller within the Class Library

Add text to URLs instead of int ID

核能气质少年 提交于 2019-12-12 15:35:27
问题 At the moment our permalinks are not correct and hinder searching e.g. https://example.com/en/blogs/19 - this should have words in the URL that Google can pick up in the search, instead of a int id that is used to retrieve from Db. Let's say an article for 'The Automotive Industry Latest' Google will give more weight in the algorithm if we had the ability to edit the link that included keywords. For example: https://example.com/en/blogs/news/The_Automotive_Industry_Latest - this link should

ASP.NET-Core 2.0 Add/remove routes after application has already started

感情迁移 提交于 2019-12-12 14:10:32
问题 I have a need to add/remove custom routes that were registered during the Configure() method of the Startup class via the IApplicaitonBuilder. Upon startup I call the MapRoute method within the UseMvc command to register a bunch of custom routes to my controllers which all work as expected. I would like to create a route management feature that allows the administrator of the API to enable/disable these custom routes which means I need the ability to add/remove routes after the application

core 2.0 and office interop - where is the microsoft.office.core package?

自闭症网瘾萝莉.ら 提交于 2019-12-12 14:05:13
问题 In a standard .NET app, I can add the COM objects for Office Core, Word, Excel, and Powerpoint. Everything works fine. The Office core assembly is needed for some commands (for example, powerpoint uses Office.Core.MsoTriState.msoFalse/True commands for some actions, and word uses AutomationSecurity via Office.Core.MsoAutomationSecurity. The problem is when I am building an asp net core app. Nuget has the packages for Excel, Word, and Powerpoint, which will work properly if I don't reference

.net core - How to properly kill started process?

假如想象 提交于 2019-12-12 12:49:59
问题 I have a dotnet core 2.0 console app that starts up another dotnet core WebAPI. The problem is, how do I cleanly kill the WebAPI process when the console app is closed? Because as of now, I can't start the process twice since it gives an error the address is in use, and I can still see the process in the task manager. Here is how I tried to do that but seems like it's missing something to completely kill all the processes: class Program { static Process cmd; static async Task Main(string[]