【发布时间】:2014-03-14 16:22:23
【问题描述】:
我在App_code 中有一个文件SiteMinder.CS,我在其中设置了访问该网页的UserID
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
}
}
}
在另一个网页UserDetails.aspx.cs 文件中,我尝试访问此UserID,但它具有NULL 值。
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
}
}
所有这些都在同一个命名空间下。请让我知道我在哪里错了。
【问题讨论】:
-
需要调用init和Application_PreRequest来初始化UserID。目前你没有给他们打电话。
标签: c# asp.net properties encapsulation