I've a file SiteMinder.CS
in App_code
where I set the UserID
who has accessed the webpage
public class SiteMinder : IHttpModule
{
public string UserID { get; set; }
public void Init(HttpApplication context)
{
context.PreRequestHandlerExecute += new EventHandler(Application_PreRequestHandler);
}
private void Application_PreRequestHandler(Object source, EventArgs e)
{
if (HttpContext.Current.Request.Headers != null)
{
NameValueCollection coll = HttpContext.Current.Request.Headers;
UserID = coll["uid"]; // Doesn't have NULL value
}
}
}
In another webpage UserDetails.aspx.cs
file I'm trying to access this UserID
but it is having NULL
value.
public partial class UserDetails : System.Web.UI.Page
{
protected string SessionUser { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
SiteMinder objSite = new SiteMinder();
SessionUser = objSite.UserID;//Returns NULL
}
}
All these are under same namespace. Please let me know where I'm wrong here.
You're creating a new SiteMinder
object. That's not the same object that had the property set on it, so the property will have the default value (null
).
You need to obtain a reference to the original SiteMinder
object which set the property - or store the value somewhere else (such as the HttpContext
).
See more on this question at Stackoverflow