Hi all... Please Explain........
What is the difference between -
1. Page.User.Identity.Name
2. HttpContext.Current.User.Identity.Name.ToString();
3. System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();
4.System.Environment.UserName;
-----------
Which statement is to be used in which scenario ??
-------
Please explain.
Please give some links/ examples/ explanation...
I have googled it, but no clear idea till date...
Loading

PradeepRank #6,279 · 271 reputationPosted Feb 12, 2015, 2:32 AM EST
for your 1st Point.
Page.User.Identity.Name
this wil check the key value which has been given in the webconfig as given below.
<deny users="me" />
for example if you checking the authentication for page user.
public partial class Login : Page { protected void Page_Load(object sender, EventArgs e) { } protected void LoggedIn(object sender, EventArgs e) { //This is redirect the user to their page switch (Page.User.Identity.Name.ToLower()) { case "me": Response.Redirect("~/me.aspx"); break; case "you": Response.Redirect("~/you.aspx"); break; case "them": Response.Redirect("~/them.aspx"); break; } } protected void Unnamed6_Click(object sender, EventArgs e) { } } More more details go this link: http://stackoverflow.com/questions/20843573/using-page-user-identity-name-in-login-pagePradeepRank #6,279 · 271 reputationPosted Feb 12, 2015, 3:00 AM EST
basicaly you need to enable
Integrated windows authenticationand the use the following:string strName = HttpContext.Current.User.Identity.Name.ToString(); you still have other methods to get the logged in user name. Now for 3. System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();For Example
void Authenticate() { string strLogin = null; try { strLogin = System.Security.Principal.WindowsIdentity.GetCurrent().Name; Session.Add("Login", strLogin); } catch (Exception ex) { } } For 4.System.Environment.UserName; Gets the user name of the person who is currently logged on to the Windows operating system. For Example:public static void Main() { Console.WriteLine(); // Console.WriteLine("UserName: {0}", Environment.UserName); }Riddhi ValechaRank #794 · 2.9K reputationPosted Mar 19, 2015, 4:27 AM EDT
For Single Sign On,
I am using statement -
"Page.User.Identity.Name" to get the User Name,
Changed the iis setting - Windows Authentication Enabled = true;
-------
My Requirement -
1. I have given a set of users (25 for now), i.e. 25 windows users.
2. My Single Sign On Portal is for these 25 users only.
---------
My Query -
1. I have written the following code on Page_Load event -
if(Page.Ispostback == false )
{
string user = Page.User.Identity.Name.Trim(); //IN//abc.xyz
string checkUser = user.Substring(3).ToString().Trim();//abc.xyz
if (checkUser is present in the database)
{
Response.Redirect("Index.aspx",false);
}
else
{
Response.Redirect ("Errorpage.aspx",false);
}
}
-------
Error-
Sometimes, even if the user is valid, the system redirects to error page.
When I removed the POstBack Condition - then system redirects to Index Page.
Now, Postback will be false on page_load everytime.
It works fine on local. But, it gives error on server.
Please give me some ways to detect issues on server....
--------
How to detect this issue?? What should I do ??
Do I need to use any other thing to implement Single Sign ON
PLease guide and explain...