asp.net-core-2.1

How do I test an https redirect in ASP.NET Core?

拜拜、爱过 提交于 2020-05-15 15:10:14
问题 Recently, I came up with unit tests for checking some redirect rules of my ASP.NET Core 2.1 application: [Fact(DisplayName = "lowercase path")] public async Task LowercaseRedirect() { var result = await this.Client.GetAsync("/BLOG/"); Assert.EndsWith("/blog/", result.RequestMessage.RequestUri.PathAndQuery, StringComparison.InvariantCulture); } [Fact(DisplayName = "add missing slash")] public async Task SlashRedirect() { var result = await this.Client.GetAsync("/blog"); Assert.EndsWith("/blog/

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

我与影子孤独终老i 提交于 2020-04-18 05:35:50
问题 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

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

Simple way to check for api key in Web API ASP.NET Core

一曲冷凌霜 提交于 2020-04-16 03:27:28
问题 I'd like to simply check for an Api Key — sent up in the Authorization header — prior to allowing certain Web API endpoints from getting hit. For the sake of this question, let's assume the ApiKey is 12345 . I just want to check the value of this Api Key prior to reaching the specific action method. I can't figure out whether or not this calls for a custom AuthorizeAttribute or an action filter. 回答1: Simply, I make a request GET with header is Authorization: apiKey 12345 The authorization

ASP.Net Core 2.1 application cannot find appsettings.json when ran as a Windows service

老子叫甜甜 提交于 2020-04-13 17:06:38
问题 I am trying to run my ASP.Net Core 2.1 application as a service on Windows 10. My application runs fine when ran using VS2017 or if I publish to a folder and then start it from within that published folder with the --console arg. However, if I use sc create to create the service, getting a Success result, and then try to run it, I get an error in the Windows Application log stating... System.IO.FileNotFoundException: The configuration file 'appsettings.json' was not found and is not optional.

ASP.Net Core 2.1 application cannot find appsettings.json when ran as a Windows service

痞子三分冷 提交于 2020-04-13 17:00:07
问题 I am trying to run my ASP.Net Core 2.1 application as a service on Windows 10. My application runs fine when ran using VS2017 or if I publish to a folder and then start it from within that published folder with the --console arg. However, if I use sc create to create the service, getting a Success result, and then try to run it, I get an error in the Windows Application log stating... System.IO.FileNotFoundException: The configuration file 'appsettings.json' was not found and is not optional.

How to keep the session alive after the browser is closed for 15 minutes using Identity in Core 2.2?

允我心安 提交于 2020-04-10 16:48:02
问题 I have an application written using C# on the top of ASP.NET Core 2.2 framework. I am using Identity to user management and user control. Currently, everytime a user closed his/her browser and open the app again, they are required to log in again. I want to change the login from a session into a cookie that expired after 15 minutes of being inactive. Here is what I have added to the Startup class public void ConfigureServices(IServiceCollection services) { services.AddDbContext

How to keep the session alive after the browser is closed for 15 minutes using Identity in Core 2.2?

被刻印的时光 ゝ 提交于 2020-04-10 16:45:13
问题 I have an application written using C# on the top of ASP.NET Core 2.2 framework. I am using Identity to user management and user control. Currently, everytime a user closed his/her browser and open the app again, they are required to log in again. I want to change the login from a session into a cookie that expired after 15 minutes of being inactive. Here is what I have added to the Startup class public void ConfigureServices(IServiceCollection services) { services.AddDbContext

How to use Active Directory Authentication in ASP.NET Core?

夙愿已清 提交于 2020-04-05 15:24:14
问题 I am using the ASP.NET Core 2.1 React SPA Microsoft template. I want to use Active Directory for user authentication. Our server runs on a corporate network using Active Directory domain identities. How can I do it? 回答1: The best way is to use Windows authentication. However, that will only work if the server you run this on is joined to the domain (or a trusted domain). If not, then you will have to use Forms Authentication, where the user enters their username and password, and you

How to use Active Directory Authentication in ASP.NET Core?

自闭症网瘾萝莉.ら 提交于 2020-04-05 15:23:50
问题 I am using the ASP.NET Core 2.1 React SPA Microsoft template. I want to use Active Directory for user authentication. Our server runs on a corporate network using Active Directory domain identities. How can I do it? 回答1: The best way is to use Windows authentication. However, that will only work if the server you run this on is joined to the domain (or a trusted domain). If not, then you will have to use Forms Authentication, where the user enters their username and password, and you