Server.TransferRequest对于IIS 6 [英] Server.TransferRequest for IIS 6

查看:500
本文介绍了Server.TransferRequest对于IIS 6的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法伪造了在IIS 6 TransferRequest的行为?具体的能力重新处理,而无需进行新的请求的客户端的整个管道?

Is there a way to fake the behavior of TransferRequest in IIS 6? Specifically the ability to re-process the whole pipeline without the client having to make a new request?

我想处理来自的Application_Error一个404错误,做一些魔术,看是否改变URL(在这种情况下,我使用的Response.Redirect重定向到新的URL),但如果真的有404我想成为了我的pretty看404页,其中有对付显示一些内容是用户会话的一部分。

I'm trying to handle a 404 error from Application_Error, do some magic to see if the URL changed (in which case I use Response.Redirect to redirect to the new URL) but if there really is a 404 I want to serve up my pretty looking 404 page which has to deal with showing some content which is part of the users session.

问题是,如果我用Server.Transfer的,请求上下文为null,在这一点上,所以我的404页崩溃。我不想用Request.Redirect因为我想浏览器的URL仍然是在缺少URL,这样的404状态code得到妥善PTED缺少的资源之间的$ P $。

The problem is that if I use Server.Transfer, The request context is null at this point so my 404 page crashes. I don't want to use Request.Redirect because I want the browser URL to still be on the missing URL so the 404 status code gets interpreted properly for the missing resource.

在IIS 7我可以使用TransferRequest这不正是我想要的东西。浏览器保留了丢失的URL和会话的上下文可用于404页code。那么,有没有办法做IIS 6类似的东西? (TransferRequest仅在IIS 7的管道模式可用,我们的生产服务器仍然在IIS 6)

On IIS 7 I can use TransferRequest which does exactly what I want. The browser retains the missing URL and Session context is available for the 404 page code. So is there a way to do something similar with IIS 6? (TransferRequest is only available in IIS 7 in Pipeline mode and our production servers are still on IIS 6)

推荐答案

一个可能的解决方案是让您的重定向有一个标志,然后作出的BeginRequest RewritePath。

One possible solution is to make your redirect with a flag, and then make RewritePath on BeginRequest.

例如,你放在的Global.asax

protected void Application_BeginRequest(Object sender, EventArgs e)
{
    if (HttpContext.Current.Request.RawUrl.EndsWith("error"))
    {
        HttpContext.Current.RewritePath("404CoolPage.aspx", false);
    }


    // .... rest code   
}

和您在您重定向

void Application_Error(object sender, EventArgs e) 
{

    //... code

    if(System.Web.HttpContext.Current.Request.QueryString.Count > 0)        
        Response.Redirect(HttpContext.Current.Request.RawUrl + "&error");
    else
        Response.Redirect(HttpContext.Current.Request.RawUrl + "?error");   
}

这样,你让重定向,并且您保留网址,因为它是。

This way, you make the redirect, and you keep the url as it is.

顺便说一句,我用了的Server.Transfer及其工作给我。这是我的错误设置和转移是使用服务器做的,我不知道在哪里你的页面与请求上下文问题

By the way, I use the the Server.Transfer and Its working to me. This is my Error setup and the Transfer is done using the server, I am not sure where your page have problem with the request context

void Application_Error(object sender, EventArgs e) 
{
    // ... log the errors ...
    string cTheFile = HttpContext.Current.Request.Path;
    // in case the error is inside the 404CoolError.aspx
    // I check for not calling my self and get a dead loop.
    if(!cTheFile.EndsWith("404CoolError.aspx"))
        Server.Transfer("~/404CoolError.aspx");
}

和在web.config中

and on web.config

<customErrors redirectMode="ResponseRewrite" ... />

这篇关于Server.TransferRequest对于IIS 6的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆