How to get the current logged in user ID in ASP.NET Core?

Update in ASP.NET Core Version >= 2.0 In the Controller: public class YourControllerNameController : Controller { private readonly UserManager<ApplicationUser> _userManager; public YourControllerNameController(UserManager<ApplicationUser> userManager) { _userManager = userManager; } public async Task<IActionResult> YourMethodName() { var userId = User.FindFirstValue(ClaimTypes.NameIdentifier) // will give the user’s userId var userName = User.FindFirstValue(ClaimTypes.Name) // will give the user’s userName // For … Read more

When should I use OWIN Katana?

In asp.net WebApi v2, the OWIN pipeline becomes the default. It is eventually going to be the standard pipeline under any asp.net project. I cannot put it better than what is written here : http://www.asp.net/aspnet/overview/owin-and-katana/an-overview-of-project-katana The section “The Open Web Interface for .NET (OWIN)” explains perfectly the goals of OWIN. Without OWIN, the asp.net bits … Read more

CustomErrors mode=”Off”

This has been driving me insane for the past few days and couldn’t get around it but have finally figured it out: In my machine.config file I had an entry under <system.web>: <deployment retail=”true” /> This seems to override any other customError settings that you have specified in a web.config file, so setting the above … Read more

How to create JSON string in C#

Using Newtonsoft.Json makes it really easier: Product product = new Product(); product.Name = “Apple”; product.Expiry = new DateTime(2008, 12, 28); product.Price = 3.99M; product.Sizes = new string[] { “Small”, “Medium”, “Large” }; string json = JsonConvert.SerializeObject(product); Documentation: Serializing and Deserializing JSON

.net localhost website consistently making get arterySignalR/poll?transport=longPolling&connectionToken= calls

This is working as intended. Artery aka BrowserLink is a real-time connection from Visual Studio to all browsers running your code. It essentially allows Visual Studio to interact with every browser. For instance if you have IE, Opera, Chrome and Firefox all running your code and you’re trying to ensure cross browser correctness; instead of … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)