asp.net-core-2.0

log4net AdoNetAppender in .Net core 2.0 not supported?

南楼画角 提交于 2020-01-13 09:39:11
问题 I'm implementing log4net AdoNetAppender in asp.net core 2.0 , but I guess it is not supporting. I have implemented log4net RollingFileAppender in core 2.0 & it worked successfully using log4.net config. So, if log4net AdoNetAppender is not supporting in core 2.0, is there any other way to insert logs to sql database in core 2.0? Thank you 回答1: I faced the same issue and solved using this nuget package in .net core solution https://www.nuget.org/packages/MicroKnights.Log4NetAdoNetAppender You

AspNet Core CookieAuthentication with injected SessionStore

老子叫甜甜 提交于 2020-01-12 18:50:37
问题 During migration of an ASPNetCore 1.1 Project to ASPNetCore 2.0, we stumbled upon a Problem with the Cookie-AuthN and its SessionStore . ASP.NET Core 1 allowed us to do something like that: public void ConfigureServices(...) { Services.AddDistributedSqlServerCache(...); Services.AddSingleton<DistributedCookieSessionStore>(); /// SQL based store } public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerfactory) { var cookieOptions = app.ApplicationServices

AspNet Core CookieAuthentication with injected SessionStore

Deadly 提交于 2020-01-12 18:50:09
问题 During migration of an ASPNetCore 1.1 Project to ASPNetCore 2.0, we stumbled upon a Problem with the Cookie-AuthN and its SessionStore . ASP.NET Core 1 allowed us to do something like that: public void ConfigureServices(...) { Services.AddDistributedSqlServerCache(...); Services.AddSingleton<DistributedCookieSessionStore>(); /// SQL based store } public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerfactory) { var cookieOptions = app.ApplicationServices

'HttpPostedFileBase' in Asp.Net Core 2.0

我与影子孤独终老i 提交于 2020-01-12 14:11:31
问题 I'm recently working on a ReactJS app that's calling an API (developed with .NET Core 2.0). My question is how to use HttpPostedFileBase in an .NET Core 2.0 API in order to get file content and save it in database. 回答1: You don't have HttpPostedFileBase in ASP.NET Core 2.0, but you can use IFormFile . [HttpPost("UploadFiles")] public async Task<IActionResult> Post(List<IFormFile> files) { long size = files.Sum(f => f.Length); // full path to file in temp location var filePath = Path

asp.net-core2.0 user auto logoff after 20-30 min

╄→尐↘猪︶ㄣ 提交于 2020-01-12 13:55:30
问题 Few days ago I have decided to upgrade my web app from asp.net core 1.1 to core 2.0. Everything seems to work fine after minor changes, except authentication does not persist longer than 20-30 minutes. We can take the default example from Visual Studio because I experience the same problem in my own webapp and in "ASP.NET Core Web Application" -> .NET Framework 4.6.1 + ASP.NET Core 2.0 + MVC + Individual User Accounts . Configuration is default and should be users logged in for 14 days:

Sharing logger between different .NET frameworks

最后都变了- 提交于 2020-01-12 08:26:09
问题 I am creating an application framework that can be shared between .Net Core 1.2, .Net Core 2.0 and .NET Framework 4.6+. So I choose the target framework of my project as .NET Standard. In my framework project I have factory class that is used to send a text message or email. On application startup, each application configures the factory with the supported services as singleton instance with DI framework. public class MyFactory : IMyFactory { private ILogger _logger; private IDictionary

How to unit test HttpContext.SignInAsync()?

半世苍凉 提交于 2020-01-12 04:44:29
问题 SignInAsync() Source Code I ran into some problems with unit testing. DefaultHttpContext.RequestServices is null I tried to create the AuthenticationService object, but I do not know what parameters to pass What should I do? How to unit test HttpContext.SignInAsync() ? Method under test public async Task<IActionResult> Login(LoginViewModel vm, [FromQuery]string returnUrl) { if (ModelState.IsValid) { var user = await context.Users.FirstOrDefaultAsync(u => u.UserName == vm.UserName && u

Json.Net and validation of Enums in Web API

旧时模样 提交于 2020-01-10 05:40:09
问题 I'm writing a web api in .Net Core 2.2. I have an enumeration as follows: using System.Runtime.Serialization; namespace MyNamespace { public enum MyEnum { [EnumMember(Value = "Some Value")] SomeValue } } If I pass in random data as MyEnum in a request using the enum I rightly get an error, but if I pass "Some Value" or "SomeValue" it passes. How do I make "SomeValue" invalid? "SomeValue" isn't in my swagger and isn't a value I want to accept. So basically, model validation passes for

how to check for entities/relationships generically

僤鯓⒐⒋嵵緔 提交于 2020-01-07 14:38:12
问题 I have entities/relationships like following A -> B; B -> C, B -> D, B -> E, ... When a user wants to delete entity A, I check whether any of its children B entities have any records for C entities, and D entities, etc and provide a detailed error message. However, the requirement is that we might end up adding more entity types such as B -> FutureEntity. Is there a way to either generically check for all of these, or atleast make sure that in the future if such an entity gets added, I modify

How to get ASP.NET Identity authentication ticket expiry in Razor Page?

耗尽温柔 提交于 2020-01-06 07:21:43
问题 I'm using identityserver4 with ASP.NET Identity, with a cookie configured with SlidingExpiration = true and ExpireTimeSpan = 20 minutes. I would like to provide the user with a warning when they are about to timeout so am trying to access the ".expiry" value in the cookie. So far I have been able to read an expiry time using the Razor code below. However this is failing to read the correct expiry time when the user refreshes their ticket. According to the Microsoft docs SlidingExpiration