asp.net-core-2.0

AddIdentity() fails “InvalidOperationException: Scheme already exists: Identity.Application”

隐身守侯 提交于 2019-12-23 07:39:13
问题 Im trying to add facebook login to my .NET Core 2.1 site Im following this , guide and more specific, this (for facebook login) After have adding the lines below to startup.cs, inside ConfigureServices-method public void ConfigureServices(IServiceCollection services) { ... services.AddIdentity<ApplicationUser, IdentityRole>() .AddEntityFrameworkStores<ApplicationDbContext>() .AddDefaultTokenProviders(); ... } I get the error message, when Im running the application. Without these lines it

.Net Core 2.0 Webjob with Scoped Dependencies

允我心安 提交于 2019-12-23 05:42:09
问题 I am building a webjob with .Net Core 2.0 set up using an IJobActivator. IServiceScopeFactory.CreateScope does not seem to work in the IJobActivator if Functions is scoped, nor within Functions if it's a singleton. I.e. public static void Main(string[] args) { IServiceCollection serviceCollection = new ServiceCollection(); serviceCollection.AddScoped<Functions>(); //Or serviceCollection.AddSingleton<Functions>(); serviceCollection.AddScoped<TelemetryScopeProvider>(); //... Other scoped

How do I use the private key from a PFX certificate stored in Azure Key Vault in .NET Core 2?

余生颓废 提交于 2019-12-23 05:02:05
问题 I've written an ASP.NET Core 2.0 website in C# and have Facebook authentication enabled, so it requires HTTPS. I'm using the native Kestrel web server to host the site and have a listener set to take the PFX certificate per MS' documentation. I can't seem to find a way for Kestrel to recognize the private key after recall from Key Vault. I know it's present, as I wrote two debug statements that indicate it is, in fact present. This is the function that I'm using to retrieve the secret, which

Asp.Net Core Area routing to Api Controller not working

南楼画角 提交于 2019-12-23 04:58:22
问题 I have an API controller hosted in an area. However, the routing doesn't seem to be working as my ajax calls keep returning 404's when trying to hit the controller actions. Breakpoints in the controller constructor are never hit. [Area("WorldBuilder")] [Route("api/[controller]")] [ApiController] public class WorldApiController : ControllerBase { IWorldService _worldService; IUserRepository _userRepository; public WorldApiController(IWorldService worldService, IUserRepository userRepository) {

Access SignalR Hub without Constructor Injection

落爺英雄遲暮 提交于 2019-12-23 04:01:27
问题 With AspNetCore.SignalR (1.0.0 preview1-final) and AspNetCore.All (2.0.6), how can I invoke a method on a hub in server code that is not directly in a Controller and is in a class that cannot be made via Dependency Injection? Most examples assume the server code is in a Controller and should 'ask' for the hub via an injectable parameter in a class that will created by DI. I want to be able to call the hub's method from server code at any time, in code that is not injected. The old SignalR had

Access SignalR Hub without Constructor Injection

巧了我就是萌 提交于 2019-12-23 04:01:05
问题 With AspNetCore.SignalR (1.0.0 preview1-final) and AspNetCore.All (2.0.6), how can I invoke a method on a hub in server code that is not directly in a Controller and is in a class that cannot be made via Dependency Injection? Most examples assume the server code is in a Controller and should 'ask' for the hub via an injectable parameter in a class that will created by DI. I want to be able to call the hub's method from server code at any time, in code that is not injected. The old SignalR had

EF Core 2.2.3 child record is not saved after update from 2.2.1

岁酱吖の 提交于 2019-12-23 03:45:06
问题 I had the below .net Core code working with Microsoft.EntityFrameworkCore.SqlServer 2.2.1. After I upgrade the dotnet core sdk to 2.2.3 it is not working. Note that the related entity is not mapped with a FK in DB. I have a partial class that has the relation and has the attribute NotMapped to make this work in 2.2.1 . I am not sure what changed and what I need to add to save header and detail record. var soHeader = new masSoHeader(); var orderToAdd = Mapper.Map(salesOrder.SalesOrderHeader,

How HttpContext RESPONSE END in ASP.NET Core

拟墨画扇 提交于 2019-12-23 02:53:16
问题 I want use mvc System.Web.HttpContext.Current.Response.End(); but trying in mvc core 2 with this code: private readonly IHttpContextAccessor _httpContextAccessor; public SmsService(IUnitOfWork uow ,IHttpContextAccessor httpContextAccessor) { _uow = uow; _uow.CheckArgumentIsNull(nameof(_uow)); _LockIPRequest= uow.Set<LockIPRequest>(); this._httpContextAccessor = httpContextAccessor; } _httpContextAccessor.HttpContext.Response.WriteAsync("</body></html>"); _httpContextAccessor.HttpContext

Hanfire not logging custom exception with metadata

元气小坏坏 提交于 2019-12-23 02:42:20
问题 I have asp.net core 2.1 application along with HangFire 1.6.17 . HangFire is configured to execute a background job at certain interval. The background job calls external API using HttpClient. If the http call fails, then the method throws custom exception with metadata. Idea is hangfire will log the exception with metadata. I followed best-practices-for-exceptions to create exception public class MyHttpRequestException : Exception { public string Content { get; private set; } public string

Launch external process (.exe) from asp.net core app

荒凉一梦 提交于 2019-12-22 22:46:36
问题 I have the following [HttpPost] public IActionResult LaunchExternalProcess() { Process.Start("C:\\Windows\\System32\\calc.exe"); return Ok(); } And this works perfectly fine on my local machine, but when deployed onto IIS 10 (windows 2016) I get no errors but it does not launch the calc on the server. I simply want to call an external .exe from a button on my page. Here is the javascript that I am using which also works on my local but no errors on server and it displays the success message $