Category Archives: C#

Visual Studio 2017 – 7 lesser known debugging tips

https://blogs.msdn.microsoft.com/visualstudio/2017/06/26/7-lesser-known-hacks-for-debugging-in-visual-studio/

2 point on “Data Breakpoints” is really useful. Sometimes we just want to debug a single instance of a type. The ability to assign an ID to an object (e.g. $1) we want to trace and set this=="$1" is just brilliant!

VS2017 has spent a lot of effort trying to make the debugger more developer friendly for multi-threaded application. Appreciate your effort, Microsoft 🙂

Windows Authentication EF Impersonation

http://stackoverflow.com/questions/1954944/impersonating-user-with-entity-framework

 

Your EF connection string is going to need to be set up for using a trusted connection.

You won’t need to set up Impersonation in your web.config, but you do need to be using Windows Authentication.

Then just do this:

using (((WindowsIdentity)HttpContext.Current.User.Identity).Impersonate())
using (var dbContext = new MyEntityFrameworkContainer())
{
    ...
}

Any code inside the curly braces of the using statements will run as the authenticated user.