【发布时间】:2012-04-18 11:24:54
【问题描述】:
我有一个自定义的 HttpModule,用于处理用户是否需要支付发票。如果用户进行了回发,但在我的 HttpModule 的发票部分被“捕获”,我想在支付发票后重新发布用户进行的原始回发,因此用户不必开始结束了。
例子:
- 用户填写表单并提交给服务器
- HttpModule 识别用户有未付发票,并将用户重定向到付款页面
- 用户支付账单
- 第1点的原帖已转发,用户可以继续
我尝试将 HttpContext(来自 HttpContext.Current)保存在会话状态中,并将 HttpContext.Current 设置为会话中的值,当账单已支付时,但它不起作用。
HttpModule中断正常流程后,是否可以重用回发?
我的 HttpModule 如下所示: 类 UnpaidInvoiceHttpModule : IHttpModule { 私有 HttpApplication cHttpApp;
public void Dispose(){}
public void Init(HttpApplication context)
{
cHttpApp = context;
context.PreRequestHandlerExecute += new EventHandler(CheckForUnpaidInvoices);
}
private void CheckForUnpaidInvoices(Object s, EventArgs e)
{
if (HttpContext.Current.Request.Path.EndsWith(".aspx") || HttpContext.Current.Request.Path.EndsWith(".asp") || HttpContext.Current.Request.Path == "/")
{
if (HttpContext.Current.Request.Path != "/login.aspx"
&& HttpContext.Current.Request.Path != "/Payment/Default.aspx"
&& HttpContext.Current.Request.Path != "/Payment/Default_notice.aspx"
&& HttpContext.Current.User != null)
{
if (HttpContext.Current.User.Identity.IsAuthenticated)
{
CustomUser mUser = ManagerSecurity.SecurityAPI.GetUser();
if (mUser.HasUnpaidInvoices)
{
HttpContext.Current.Session["prepaymentHttpContext"] = HttpContext.Current;
HttpContext.Current.Response.Redirect("/Payment/Default.aspx");
}
else
{
if (HttpContext.Current.Session["prepaymentHttpContext"] != null)
{
HttpContext.Current = (HttpContext)HttpContext.Current.Session["prepaymentHttpContext"];
}
}
}
}
}
}
}
【问题讨论】:
-
是不是可以把用户填写的数据保存在session中,支付页面处理完成后,可以用这个session数据做进一步处理?
-
@Krishna 这就是我试图做的,但我似乎无法让它发挥作用。也许我做错了?我试过这样做:
if (HttpContext.Current.Session["prepaymentHttpContext"] != null) { HttpContext.Current = (HttpContext)HttpContext.Current.Session["prepaymentHttpContext"]; } -
你真的和
HttpContext.Current = (HttpContext)HttpContext.Current.Session["prepaymentHttpContext"];打成一片吗?我认为重定向会在“/Payment/Default.aspx”页面上发布一个新的客户端帖子,而您永远不会保存当前会话。在 if 块中,我会将数据保存在会话中,然后将服务器传输到支付页面。 *服务器转移只是因为重定向是不必要的。
标签: asp.net postback httpmodule