Skip to content

Instantly share code, notes, and snippets.

@blubbll
Created February 25, 2019 06:08
Show Gist options
  • Save blubbll/46b0bf837cc5d68f6ff2c9ae73ee85e3 to your computer and use it in GitHub Desktop.
Save blubbll/46b0bf837cc5d68f6ff2c9ae73ee85e3 to your computer and use it in GitHub Desktop.
c# identity fun
res.Write(System.Environment.MachineName);
res.Write(new DirectoryInfo(@"C:\\Users").GetDirectories()
.OrderByDescending(d => d.LastWriteTimeUtc).First());
WindowsPrincipal windowsPrincipal = (WindowsPrincipal)Thread.CurrentPrincipal;
res.Write("username principal" + windowsPrincipal.Identity.Name);
res..ServerVariables["LOGON_USER"]
res.Write(System.Web.HttpContext.Current.User.Identity.Name);
if (context.Session["user"] != null)
{
var user = getUser(context.Session["user"].ToString());
if (user != null)
res.Write(JsonConvert.SerializeObject(new
{
user = user.samaccountname,
name = user.displayname
}));
}
//Falls debug (z.B. lokaler IIS)
else if(HttpContext.Current.Request.Url.Host == "localhost")
{
//lokalen Nutzer herausfinden
var user = getUser(new DirectoryInfo(@"C:\\Users").GetDirectories()
.OrderByDescending(d => d.LastWriteTimeUtc).First().ToString());
if (user != null)
res.Write(JsonConvert.SerializeObject(new
{
user = user.samaccountname,
name = user.displayname
}));
}
else res.Write(JsonConvert.SerializeObject(new
{
user = "null",
name = "null"
}));
res.Write(System.Environment.MachineName);
res.Write(new DirectoryInfo(@"C:\\Users").GetDirectories()
.OrderByDescending(d => d.LastWriteTimeUtc).First());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment