- C# code
public void Init(HttpApplication a)
{
a.AcquireRequestState += new EventHandler(a_BeginRequest);
}
void a_BeginRequest(object sender, EventArgs e)
{
HttpApplication a = (HttpApplication)sender;
HttpSessionState s = (HttpSessionState)a.Context.Session;
if (s["user"] == null)
{
a.Context.Response.Redirect(@"~\Forms\backstage\login");
--在这里如果通过重定向过去页面就报Sesson没将对象设置到实例..
--但是我通过server派遣过去的话就能显示 由于页面路径不一样 Login的样式
--图片全部加载不了 ,求高手指点(如果在同一目录派遣都会报上面的那个错误!)
}
}
public void Dispose()
{
throw new Exception("The method or operation is not implemented.");
}}
上面代码是这样写的 理论没错...问题就是报错了
------解决方案--------------------------------------------------------
public class TestModule : IHttpModule
{
public void Dispose()
{
}
public void Init(HttpApplication context)
{
context.AcquireRequestState += (o, e) =>
{
HttpApplication app = (HttpApplication)o;
if (app.Context.Handler.ToString().EndsWith("aspx"))
{
app.Session["Test"] = "1";
app.Response.Write(app.Session["Test"].ToString());
}
};
}
}