.net-core

RedirectToAction starts new session

≡放荡痞女 提交于 2021-02-10 07:56:21
问题 I have a controller which logins in my user. Assuming its an existing user and the password is correct i check if they have 2fa enabled. AccountControler login method public async Task<IActionResult> Login(LoginViewModel model, string returnUrl = null) { ViewData["ReturnUrl"] = returnUrl; if (ModelState.IsValid) { // This doesn't count login failures towards account lockout // To enable password failures to trigger account lockout, set lockoutOnFailure: true var result = await _signInManager

How to use web sockets in C# .NET Core 3.1?

心不动则不痛 提交于 2021-02-10 07:49:25
问题 I am trying to implement live notifications in my web application. Only the users which are administrators in my web app should see the notifications. So I setup the web socket in my startup.cs file which I think is not the right way Startup.cs var webSocketOptions = new WebSocketOptions() { KeepAliveInterval = TimeSpan.FromSeconds(120), ReceiveBufferSize = 4 * 1024 }; app.UseWebSockets(webSocketOptions); app.Use(async (context, next) => { if (context.Request.Path == "/ws") { if (context

Security token from TokenValidatedContext from the OnTokenValidated event listener is missing last string segment

那年仲夏 提交于 2021-02-10 07:48:17
问题 I'm using the Microsoft.AspNetCore.Authentication.JwtBearer and System.IdentityModel.Tokens.Jwt for my .NET Core project. Whenever I generate a new token I store that to the database. First of all this is how I generate a new token public string GenerateToken(Dictionary<string, object> payload) { DateTime tokenExpiresAt = DateTime.Now.AddMilliseconds(1); // from config byte[] symmetricKey = Convert.FromBase64String("secret"); // from config SymmetricSecurityKey symmetricSecurityKey = new

How can I resolve a decorator using a particular instance of a component or another decorator object in .net core

▼魔方 西西 提交于 2021-02-10 07:01:36
问题 After learning about the Decorator Pattern with typical Coffee example where Decorator Pattern saves us from the class explosion problem, I wrote some code to use and see it myself. Lets take a look at the UML first... and here is the code: Component ICofee defination: public interface ICoffee { string Name { get; } decimal Cost { get; } } LatteCoffee definition: public class LatteCoffee : ICoffee { public string Name { get; } = "Latte"; public decimal Cost => 2.00m; } Decorators

.net core project dependencies - yellow triangle

故事扮演 提交于 2021-02-10 06:47:39
问题 My .Net Core project has a yellow triangle on dependencies, but when I open it up, none of the child entries have a yellow triangle. When I hover over dependencies, I don't see any tooltip telling me what's wrong. How can I check to see what is causing this yellow triangle to show up? I did what @oandreeeee suggested and increased the log level of my build and I noticed this: C:\Program Files\dotnet\sdk\2.2.104\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.ConflictResolution.targets(41,5):

dotNet core (console app) with Enterprise Library Data (EnterpriseLibrary.Data.NetCore) and JSON

喜夏-厌秋 提交于 2021-02-10 06:27:06
问题 I am trying to use: EnterpriseLibrary.Data.NetCore .nuget\packages\enterpriselibrary.data.netcore\6.0.1313 https://www.nuget.org/packages/EnterpriseLibrary.Data.NetCore/ .NET Core 2.1 I have the following JSON { "ConnectionStrings": { "MyDefaultConnectionName": "Server=.\\MyInstance;Database=MyDB;Trusted_Connection=True;MultipleActiveResultSets=true" } } And this code works fine (in my Program.cs dotnet console app) (simple showing my appsettings.json is being picked up, and it looks like my

LINQ how to return last date and difference between first and last count

寵の児 提交于 2021-02-10 06:16:25
问题 I have a table with the following column and sample data: acteename updated_at count (count is not sorted in db) dev-52 2/7/2020 5:56:43 PM 1 dev-52 2/7/2020 5:56:52 PM 2 dev-52 2/7/2020 5:57:00 PM 3 dev-52 2/7/2020 5:57:49 PM 4 dev-52 2/7/2020 5:59:19 PM 5 dev-52 2/7/2020 6:01:51 PM 6 dev-52 2/7/2020 6:06:21 PM 7 dev-52 2/7/2020 6:14:51 PM 8 dev-52 2/7/2020 6:31:23 PM 9 dev-52 2/7/2020 6:47:54 PM 10 dev-52 2/7/2020 7:04:26 PM 11 dev-52 2/7/2020 7:20:58 PM 12 I want to return diff between

Cannot compile template C++/CLI (.NET Core 3.1) project via dotnet build command

若如初见. 提交于 2021-02-10 05:37:15
问题 Install latest stable Visual Studio 2019 16.4.2 (check .NET Core Development and Desktop development with C++ workloads, also make sure that C++/CLI support component in checked). Create new project with CLR Class Library (.NET Core) template (or CLR Empty Project (.NET Core) if you like). Compilation via dotnet build command will fail ( dotnet build CLRNetCoreTest.sln /p:Configuration=Debug /p:Platform=x86 ): Compilation via msbuild command is successfull ( "%ProgramFiles(x86)%\Microsoft

Understanding BLOCKED_TIME in PerfView

假如想象 提交于 2021-02-10 05:13:34
问题 We are suspecting that we're experciencing thread pool starvation on a server that is running a couple of ASP.NET Core APIs and a couple of .NET Core consoles. I ran perfview one one of our servers were we are suspecting problems with thread pool starvation. However I'm having a bit of trouble analyzing the results. I ran PerfView /threadTime collect for about 60 seconds. And this is the result I got (I chose one to look at one of our ASP.NET Core APIs): Looking at "By Name" we can see that

run additional logic besides [Authorize] annotation

不想你离开。 提交于 2021-02-10 00:34:54
问题 I'm using the Microsoft.AspNetCore.Authentication.JwtBearer and System.IdentityModel.Tokens.Jwt for my .NET Core project. Whenever I generate a new token I store that to the database. When a user signs out, I remove it from the database to invalidate it (I also remove the expired ones from the database with a job). When a user tries to access a route protected by the [Authorize] annotation I want to check if that token exists in the database. If not, I send a 401. In my Startup in the