asp.net-core-2.0

How do I delete a node in appsettings.json using appsettings.Development.json?

时间秒杀一切 提交于 2020-01-05 04:14:11
问题 I am struggling a bit with how the appsettings.Development.json overrides or otherwise merges with the appsettings.json . I am not sure how to "clear" a node out of appsettings.json by using the appsettings.Development.json file. For reference, I am using the default builder as seen here https://github.com/aspnet/MetaPackages/blob/rel/2.0.0-preview1/src/Microsoft.AspNetCore/WebHost.cs#L159-L160 appsettings.json { "Policy": { "roles": [ { "name": "inventoryAdmin", "subjects": [ "bob", "alice"

.net core 2 Google Authentication login loop

馋奶兔 提交于 2020-01-04 04:39:09
问题 I am trying to authenticate using google in .net core 2 and have done what seems to be the very simple set up required for this: 1) Added app.UseAuthentication(); to Configure(..) in startup.cs 2) Added to ConfigureServices(..) startup.cs services.AddAuthentication(options => { options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme; options.DefaultChallengeScheme = GoogleDefaults.AuthenticationScheme; }) .AddCookie() .AddGoogle(options => { options.ClientId = Configuration[

JS Fetch API not working with ASP.NET Core 2 Controllers with Authorize attribute

耗尽温柔 提交于 2020-01-04 03:58:09
问题 I'm having the following code on the client side: fetch("/music/index", { headers: { "Content-Type": "application/json" } }) .then(response => { if (!response.ok) { throw response; } return response.json(); }) .then(json => { console.log("Done! It's all good"); }) .catch(response => console.log(response)); Unfortunately this doesn't even reach the MusicController (server-side), which looks as follows (simplified to illustrate the point): [Authorize] public class MusicController : Controller {

`SwaggerRequestExample` is being ignored

。_饼干妹妹 提交于 2020-01-03 15:20:22
问题 As I was adding swagger to my API, I wanted to get default values and response examples. I added the NuGet packages and tried to follow this tutorial. The SwaggerResponseExample attribute works properly but the SwaggerRequestExample seems to be simply ignored. With my action defined as follow [SwaggerRequestExample(typeof(int), typeof(PersonExamples.Request))] [SwaggerResponseExample(200, typeof(PersonExamples.Response))] /* more attribute & stuff */ public IActionResult Get(int id) { /*

AWS Cognito User Pools and OpenId

不想你离开。 提交于 2020-01-03 14:08:47
问题 I am playing around with Amazon Cognito and after reading some of the docs and creating a user pool I am running into some issues. I believe that a cognito user pool can be used with OpenId to redirect the user to a hosted UI for user authentication (without federating out to another provider). I have tried to use the authentication options in DotNetCore 2 to do this as this is something I have done previous with other providers. I have the following: services.AddAuthentication(options => {

.NET Core 2.x how to get the current active local network IPv4 address?

这一生的挚爱 提交于 2020-01-03 10:56:27
问题 On which is running the WebService. Like the one I can get in cmd.exe > ipconfig : What I would like to achieve is automatic IP configuration of Kestrel, like: .UseKestrel(opts => { opts.Listen(/*LocalIPv4ActiveAddress*/, 5000); }) So I can switch my development machines with different active network interfaces (WiFi || Ethernet) and different local network IP addresses. 回答1: You can try something like this: // order interfaces by speed and filter out down and loopback // take first of the

ASP .Net Core with Kestrel implement SSL

帅比萌擦擦* 提交于 2020-01-03 04:57:11
问题 i'm facing problem when implementing ssl to my web. My web work as web services for android and ios. All goes very smooth until i implement the SSL certificates, suddenly the android (most of android except samsung) throw this error : E/ErrorHTTP: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found. then i google and landed to here : google says about the error support the google statement work around for the error to accept the not valid ssl it says

How to get connection string from appsettings.json inside custom filter in .net core

左心房为你撑大大i 提交于 2020-01-03 04:53:07
问题 I have a controller EBisUserController which contains a public property ConnectionString obtained from appsettings.json through dependency injection. The controller has an attribute filter 'EBisUserAuthResourceFilter' requiring use of the property ConnectionString found in the controller. What is the most performant method to access ConnectionString. I have a working example of what I want, but know this is not the correct way of doing this as it must open and read the file for each

ObjectDisposedException on a ASP.NET Core 2.0 MVC custom database initializer class

*爱你&永不变心* 提交于 2020-01-03 04:25:12
问题 I'm getting the following exception in my custom database initializer class: System.ObjectDisposedException occurred HResult=0x80131622 Message=Cannot access a disposed object. A common cause of this error is disposing a context that was resolved from dependency injection and then later trying to use the same context instance elsewhere in your application. This may occur if you are calling Dispose() on the context, or wrapping the context in a using statement. If you are using dependency

How to create two type of users with identity and .net core 2

两盒软妹~` 提交于 2020-01-03 03:23:33
问题 I start to develop an web application with .net core 2 and web service.. when a user registers on the site, he can choose whether he is a company or a simple user, so I store the data in a specific table but the login data are stored in AspNetUsers. How can i handle it with Identity in .net core? 回答1: Simply inherit from ApplicationUser , i.e.: public class CompanyUser : ApplicationUser {} public class SimpleUser : ApplicationUser {} By default, EF will implement inheritance via STI (single