RonakThakkar
1/22/2016 - 1:03 PM

.NET-Security-UserIdentity.cs

// How to get Current Use Identity in ASP.NET
System.Web.HttpContext.Current.User.Identity

// How to get Current Use Identity in .NET (C#)
System.Threading.Thread.CurrentPrincipal.Identity

// How to get current logged in user credentials in .NET (to pass in RESTShartp, Simple.OData.Client)
ICredentials credentials = CredentialCache.DefaultCredentials;

// Windows Authentication - Pass current application / user identity to ASP.Net Web API using RestSharp
RestClient client = new RestClient("http://localhost:8004/api");
client.Authenticator = new NtlmAuthenticator();

// Windows Authentication - Pass current application / user identity to ASP.Net OData Web API using Simple.OData.Client
ODataClientSettings settings = new ODataClientSettings("http://localhost:8004/odata", CredentialCache.DefaultCredentials);
ODataClient oDataClient = new ODataClient(settings);
var result = await oDataClient.For<Category>().FindEntriesAsync();