asp.net-core-2.0

Is it possible/sensible to split ASP.Net Core 2 (.NET Framework) Web Api into Class Library and Hosting projects?

我的梦境 提交于 2019-12-05 04:24:21
I'm trying to port an existing WCF Web API (targeting .NET Framework 4.6.1) to ASP.Net Core 2 using Visual Studio 2017 (v15.4.5) and am having trouble figuring out good/common/supported ways to organize projects, and what types of project they should be. For example: Single project for Server and Hosting, or Class Library for Server and Console application for Hosting Windows Classic Desktop project for Console application and (new style csproj) Web Application for Server library, or both Web Applications (one outputting a Class Library, the other a Console Application) I have the sneaking

Authorize one app service from another (no user interaction) in ASP.NET Core 2.0

非 Y 不嫁゛ 提交于 2019-12-05 04:10:38
问题 I have a Web API app in Azure facing internet (PubWeb), so it's used from anywhere. And I created a Web API (again, in Azure, let's call it InWeb). And I want strong security rules: InWeb must be used only by the PubWeb. This might involve some network security - that's an easy part (in Azure). PubWeb must be authorized by Azure AD somehow in order to use InWeb services. Service Principals, certificates, etc comes to mind. But I'm not sure. So what's the best possible solution for 2? UPDATE -

Why does Scoped service resolve as two different instances for same request?

时间秒杀一切 提交于 2019-12-05 04:00:18
I have a simple service that contains a List<Foo> . In Startup.cs, I am using the services.addScoped<Foo, Foo>() method. I am inject the service instance in two different places (controller and middleware), and for a single request, I would expect to get the same instance. However, this does not appear to be happening. Even though I am adding a Foo to the List in the Controller Action, the Foo list in the Middleware is always empty. Why is this? I have tried changing the service registration to a singleton, using AddSingleton() and it works as expected. However, this has to be scoped to the

How to execute .Net Core 2.0 Console App using Windows Task Scheduler?

浪尽此生 提交于 2019-12-05 03:47:24
I have one Console App which is created using asp.net Core 2.0 in VS2017 . Now I want to run this application on particular time period repeatedly (like service). So I have tried this using Windows Task Scheduler but when we create task using Task Scheduler it ask for .exe file of Console app. (please check below pic) But as you can see that When we create Console App using .Net Core 2.0 there will no .exe file under bin/debug folder. Anyone have idea that how to schedule a .net Core 2.0 console app using Windows Task Scheduler ? Any suggestions will be highly appreciated ! Thanks, Just call

Re-target .NET Core to net471, net 472

ε祈祈猫儿з 提交于 2019-12-05 02:01:08
My .Netcore 2.0 project can target net471 . But when I upgraded to .NET 2.1, I can't retarget net471 or net472 Can I retarget in the latest version of .the NET core? Severity Code Description Project File Line Suppression State Error NU1202 Package Microsoft.AspNetCore.App 2.1.0 is not compatible with net471 (.NETFramework,Version=v4.7.1). Package Microsoft.AspNetCore.App 2.1.0 supports: netcoreapp2.1 (.NETCoreApp,Version=v2.1) and Severity Code Description Project File Line Suppression State Error NU1202 Package Microsoft.AspNetCore.App 2.1.0 is not compatible with net472 (.NETFramework

Cookie expiry in ASP.NET Core 2.0 with Identity

五迷三道 提交于 2019-12-05 01:11:40
问题 Environment: ASP.NET Core 2.0, Identity with cookies. In Startup.ConfigureServices() there is this: services.ConfigureApplicationCookie(options => { options.ExpireTimeSpan = TimeSpan.FromDays(14); options.Cookie.Expiration = TimeSpan.FromDays(14); }); The first is from CookieAuthenticationOptions . The second is from CookieBuilder . The docs also mention Microsoft.AspNetCore.Http.CookieOptions.Expires (though it's not available in that lambda). What is the difference between these? What is

The name WebHost does not exists in current context

房东的猫 提交于 2019-12-05 00:55:00
I'm migrating from ASP.NET Core 1.x to v2.0 with the help of following post on docs.microsoft: https://docs.microsoft.com/en-us/aspnet/core/migration/1x-to-2x/ I'm almost done with all the changes mentioned in that post. But there is one error that is causing troubles. Here is my Program.cs file: using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.Configuration; namespace MeridiaCoreAPI { public class Program { public static void Main(string[] args) { BuildWebHost(args).Run(); } public static IWebHost BuildWebHost(string[] args) => WebHost

ASP.NET Core 2.1 Custom RoleProvider with Windows Authentication

自闭症网瘾萝莉.ら 提交于 2019-12-04 23:58:05
问题 I am migrating applications away from the ASP.Net MVC 5 framework to the new .Net Core 2.1. I used Windows Authentication with a Custom RoleProvider in the MVC 5 Projects as shown in the link below. ASP.NET MVC How to create a custom role provider How do I accomplish the same in Core 2.1 as it does not seem to contain RoleProvider capability? Every example I come across uses Individual Accounts with IdentityUser and IdentityRole. My custom tables for User and Roles : public class User {

Execute SQL command in Entity Framework Core 2.0 to delete all data in a table

倾然丶 夕夏残阳落幕 提交于 2019-12-04 22:51:38
I want to execute an SQL command from Entity Framework Core 2.0, but I can't figure out how to do so. 1.- The reason why I need to, is that I want to delete all data from a database table, and using Context.remove or Context.removeRange would produce many calls to DB (one for each data in the table). 2.- I've read that there is a method .ExecuteSqlCommand to accomplish that, but that method is not present in my Context.Database (maybe in Core 2.0 it was removed?). Here is the source of the info: Dropping table In Entity Framework Core and UWP So, basically I need to delete a table from code

Adding Angular Material to Asp.Net Core 2 SPA

喜欢而已 提交于 2019-12-04 21:57:40
I cant seem to get this to work. The bits and pieces I find on SO and the net are out of date and seem incomplete. Here is my package.json: { "name": "MyProj.Site", "private": true, "version": "0.0.0", "scripts": { "test": "karma start ClientApp/test/karma.conf.js" }, "devDependencies": { "@angular/animations": "5.1.1", "@angular/common": "5.1.1", "@angular/compiler": "5.1.1", "@angular/compiler-cli": "5.1.1", "@angular/core": "5.1.1", "@angular/forms": "5.1.1", "@angular/http": "5.1.1", "@angular/platform-browser": "5.1.1", "@angular/platform-browser-dynamic": "5.1.1", "@angular/platform