How to get the current user’s Active Directory details in C#

The “pre Windows 2000” name i.e. DOMAIN\SomeBody, the Somebody portion is known as sAMAccountName. So try: using(DirectoryEntry de = new DirectoryEntry(“LDAP://MyDomainController”)) { using(DirectorySearcher adSearch = new DirectorySearcher(de)) { adSearch.Filter = “(sAMAccountName=someuser)”; SearchResult adSearchResult = adSearch.FindOne(); } } someuser@somedomain.com.au is the UserPrincipalName, but it isn’t a required field.

IIS7: Setup Integrated Windows Authentication like in IIS6

To enable the Windows Authentication on IIS7 on Windows 7 machine: Go to Control Panel Click Programs >> Programs and Features Select “Turn Windows Features on or off” from left side. Expand Internet Information Services >> World Wide Web Services >> Security Select Windows Authentication and click OK. Reset the IIS and Check in IIS … Read more

Connection string using Windows Authentication

Replace the username and password with Integrated Security=SSPI; So the connection string should be <connectionStrings> <add name=”NorthwindContex” connectionString=”data source=localhost; initial catalog=northwind;persist security info=True; Integrated Security=SSPI;” providerName=”System.Data.SqlClient” /> </connectionStrings>

How to authorize CORS preflight request on IIS with Windows Authentication

There are several ways to accomplish this, other answers can be found on this similar question –> Angular4 ASP.NET Core 1.2 Windows Authentication CORS for PUT and POST Gives 401 CORS Module It is possible to configure IIS by using the CORS Module. As seen here: https://blogs.iis.net/iisteam/getting-started-with-the-iis-cors-module And further information available here: https://blogs.iis.net/iisteam/getting-started-with-the-iis-cors-module The IIS … Read more

Windows authentication in asp.net 5

Mark’s answer is still valid in ASP.Net RC1. There are some additional steps to tie it all together (I don’t have enough reputation to comment on his solution): Install WebListener from NuGet Add the following usings to Startcup.cs: using Microsoft.AspNet.Http.Features; using Microsoft.Net.Http.Server; Add Mark’s code snippet in the Configure method before app.UseMvc: // If we’re … Read more

Impersonate using Forms Authentication

Impersonating a user using Forms Authentication can be done. The following code does work. The Visual Studio Magazine article referred to by Robert is an excellent resource. There are a some issues with the example code in the article, so I’ve included some working code below. Note: If you are using Visual Studio, make sure … Read more

Native Library sqljdbc_auth.dll already loaded in another classloader

Each web application has its own Classloader (isolating them). When you call the Class.forName() method, there is a static block which is trying to load the shared library (dll file) – so both your web apps are trying to load the shared lib, hence the error message when the second one attempts to load. The … Read more

Making a web request to a web page which requires windows authentication

You should use Credentials property to pass the windows credentials to the web service. If you wish to pass current windows user’s credentials to the service then request.Credentials = CredentialCache.DefaultCredentials; should do the trick. Otherwise use NetworkCredential as follows: request.Credentials = new NetworkCredential(user, pwd, domain);

Connecting to MS SQL Server with Windows Authentication using Python?

You can specify the connection string as one long string that uses semi-colons (;) as the argument separator. Working example: import pyodbc cnxn = pyodbc.connect(r’Driver=SQL Server;Server=.\SQLEXPRESS;Database=myDB;Trusted_Connection=yes;’) cursor = cnxn.cursor() cursor.execute(“SELECT LastName FROM myContacts”) while 1: row = cursor.fetchone() if not row: break print(row.LastName) cnxn.close() For connection strings with lots of parameters, the following will accomplish … Read more