Skip to content

Instantly share code, notes, and snippets.

@tslothorst
tslothorst / GetFullApplicationPathCS.md
Created December 6, 2021 14:52
Get your application path in C#

Finding out where your application runs in C#

Sometimes you might need to know where your application is running, for instance if you want to open a file relative to that position. With desktop apps this is more straightforward but web applications run within IIS and any attempt to navigate to a relative path will fail because you start out within a directory from the IIS webserver.

Here is quick way to find out where you're application is running:

public static string GetFullApplicationPath()
{
  return HttpRuntime.AppDomainAppVirtualPath != null ? HttpRuntime.AppDomainAppPath : Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
}
@tslothorst
tslothorst / ADGroupsRolesASPNET.md
Created December 6, 2021 14:16
How to enable and use active directory groups as roles for authorization in ASP.NET web applications

Using Active Directory groups as roles within ASP.NET Framework

When you have an ASP.NET (.NET Framework) web application and you wish to use Active Directory groups as roles within the application it's not that difficult once you know how. Make sure your project uses Windows Authentication, if you didn't set this up when you started the project you can add it later.

Add this to your web.config file:

  <system.web> 
  // Omitted for brevity