I am writing an intranet application in ASP.NET 2.0 which should automatically obtain a user's username.
The code below retrieves the username when I run in debug-mode through
"Web Developer Express", but when I try to run the same code through
IIS it is unable to retrieve the username.
Could anyone shed some light on this?
Regards,
Alex
http://localhost/src/
Welcome Unknown user.
http://localhost:1036/helpdesk/Default.aspx
Welcome D3MF2Q1J\alex.
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
public String getUser()
{
return
(Page.User.Identity.Name.Equals("") ?
(HttpContext.Current.User.Identity.Name.Equals("") ? ""
:HttpContext.Current.User.Identity.Name) : Page.User.Identity.Name);
}
}