Asp.net 在HttpModule中传输请求时,新页面中的会话为空
总之,我正在尝试实现一个HttpModule(IHttpModule),以捕获页面请求并重定向到新页面。不幸的是,我似乎无法在新页面中使用Asp.net 在HttpModule中传输请求时,新页面中的会话为空,asp.net,session,httpmodule,Asp.net,Session,Httpmodule,总之,我正在尝试实现一个HttpModule(IHttpModule),以捕获页面请求并重定向到新页面。不幸的是,我似乎无法在新页面中使用会话。因为会话为空 这是我的代码。请复习一下 public class MyModule : IHttpModule { public void Init(HttpApplication context) { context.BeginRequest += new EventHandler(context
会话。因为会话
为空
这是我的代码。请复习一下
public class MyModule : IHttpModule
{
public void Init(HttpApplication context)
{
context.BeginRequest += new EventHandler(context_BeginRequest);
}
void context_BeginRequest(object sender, EventArgs e)
{
....
HttpContext.Current.Server.Transfer("newpage.aspx");//redirect to new page.
}
}
在newpage.aspx
中,存在一个异常,即代码HttpContext.Current.Session[xxx]
的对象引用未设置为对象的实例,因为HttpContext.Current.Session
为空。
有人能告诉我发生了什么事吗?
谢谢
更新
总之,如果我使用HttpContext.Current.Response.Redirect
重定向url,我会发现。一切都好。我的意思是,会话
对象在使用之前就被启动了。但这对服务器.传输
不起作用
我已经知道了这两者的区别 包含2个模块的正常aspx运行时管道是:
--> HttpModule_1.BeginRequest(); --> HttpModule_2.BeginRequest(); --> HttpHandler(Page)
<-- HttpModule_1.EndRequest(); <-- HttpModule_2.EndRequest(); <-- HttpHandler(Page)
-->HttpModule_1.BeginRequest();-->HttpModule_2.BeginRequest();-->HttpHandler(第页)
你能显示第一页和第二页的URL吗?您可能会转到不同协议的单独域。@这两个协议都在同一个应用程序中。URL看起来像来自http://localhost:7778/orginalpage.aspx
重定向到http://localhost:7778/b/c/newpage.aspx
。谢谢