asp.net-core-2.0

How to correctly and safely dispose of singletons instances registered in the container when an ASP.NET Core app shuts down

陌路散爱 提交于 2020-04-18 05:35:29
问题 I am looking for guidance on how to correctly and safely dispose of registered singleton instances when my ASP.NET Core 2.0 app is shutting down. According to the following document, if I register a singleton instance (via IServiceCollection) the container will never attempt to create an instance (nor will it dispose of the instance), thus I am left to dispose of these instances myself when the app shuts down. https://docs.microsoft.com/en-us/aspnet/core/fundamentals/dependency-injection?view

Wont add dependencies because of missing service fabric packages

坚强是说给别人听的谎言 提交于 2020-04-13 23:01:59
问题 Starting a new empty .NET Core 2 class library i try to add any dependency with nuget i get this error Error The local source 'C:\Program Files\Microsoft SDKs\Service Fabric\packages' doesn't exist. But service fabric should have nothing to do with this solution . Also the solution builds succesfully 回答1: I faced the same error. There was service fabric installed but I decided to delete it. Then after that, this error started to appear. All you have to do is create an empty packages folder C:

Wont add dependencies because of missing service fabric packages

怎甘沉沦 提交于 2020-04-13 22:54:53
问题 Starting a new empty .NET Core 2 class library i try to add any dependency with nuget i get this error Error The local source 'C:\Program Files\Microsoft SDKs\Service Fabric\packages' doesn't exist. But service fabric should have nothing to do with this solution . Also the solution builds succesfully 回答1: I faced the same error. There was service fabric installed but I decided to delete it. Then after that, this error started to appear. All you have to do is create an empty packages folder C:

Wont add dependencies because of missing service fabric packages

拜拜、爱过 提交于 2020-04-13 22:50:40
问题 Starting a new empty .NET Core 2 class library i try to add any dependency with nuget i get this error Error The local source 'C:\Program Files\Microsoft SDKs\Service Fabric\packages' doesn't exist. But service fabric should have nothing to do with this solution . Also the solution builds succesfully 回答1: I faced the same error. There was service fabric installed but I decided to delete it. Then after that, this error started to appear. All you have to do is create an empty packages folder C:

Can I use MvcJsonOptions configured during Startup for serialization in custom middleware?

寵の児 提交于 2020-04-13 17:19:49
问题 I am building an ASP.NET Core Api with a middleware for global exception handling. In Startup class, I configured some JSON options which are to be used for all controllers. public void ConfigureServices(IServiceCollection services) { services.AddMvc() .AddJsonOptions(options => { options.SerializerSettings.ContractResolver = new DefaultContractResolver() { NamingStrategy = new SnakeCaseNamingStrategy() }; options.SerializerSettings.Converters.Add(new StringEnumConverter()); }); } Then, I

IServerAddressesFeature addresses empty when running under dotnet.exe

笑着哭i 提交于 2020-04-13 04:58:10
问题 I have a ASP.NET Core 2.0 web application, where I need to pass the application's URL out during startup for the purposes of integration into something else. When running under Visual Studio (IIS Express), IApplicationBuilder.ServerFeatures.Get<IServerAddressesFeature>().Addresses contains the URL my application is bound to (e.g. http://localhost:1234 ). When run using dotnet.exe myapp.dll , the same collection is empty, however, I get a line on stdout saying Now listening on: http:/

Can't read swagger JSON from https://localhost:44374/swagger/v1/swagger.json in asp.net core 2.0

寵の児 提交于 2020-04-11 17:59:05
问题 I am having trouble adding swaggerUI to my asp.net core 2 project. Its is not able to load the swagger.json file. I am using a custom css and layout for this documentation. below is my startup class and index.cshtml for swagger. public void ConfigureServices(IServiceCollection services) { services.AddSingleton(provider => Configuration); services.AddTransient<IRegistrationRepository, ServiceUtilities>(); services.AddTransient<IClientServiceConnector, ClientServiceValidation>(); services

csp-report endpoint in asp.net core

好久不见. 提交于 2020-04-10 03:20:41
问题 I'm trying to set up CSP in an asp.net core webapp, and the CSP part works fine, I can see the violations in the browser console as they are sent to the report-uri endpoint. However, I cannot seem to create the correct method in a controller to receive these messages! I create a method in the controller as: [HttpPost] [AllowAnonymous] public IActionResult UriReport(CspReportRequest request) { _log.LogError("CSP violation: " + request); return Ok(); } and it will be called, but the 'request'

How to add multiple policies in action using Authorize attribute using identity 2.0?

倖福魔咒の 提交于 2020-04-08 00:01:31
问题 I am identity 2.1.2 with asp.net core 2.0, I have application claim table which have claim type and claim value i.e Assets ,Assets Edit,Assets, Assets View, where claim types are same with distinct claim values and I am creating policies using claim type name which is working fine for me no clue about how to add multiple policies in one action. Below code is being used in startup file to create policies. services.AddAuthorization(options => { var dbContext =

Authentication based dynamically on Authorization header-scheme in non-MVC Asp.Net Core 2.x

こ雲淡風輕ζ 提交于 2020-03-23 08:55:14
问题 I'm creating an API, which does not use MVC , but rather generic middleware(s). It should be possible to be authenticated against both Basic and (Jwt) Bearer scheme (I'm aware of the security flaws of Basic Auth) I can easily register both schemes in the services, but app.UseAuthentication middleware will only attempt to authenticate against the default scheme (this is intentional and described in the documentation). Allowing multiple scheme for the same endpoint can be done in MVC by