在ReDirect中获取完整的aspx错误路径



我正在使用asp.net (.net 3.5)应用程序。并需要一个重定向页面(自定义错误)例如,如果我点击下面的URL(页面已经移动到不同的URL)

http://localhost: 62203/page2.aspx

在服务器localhost:62203上,我在web.config中使用以下内容:

<customErrors defaultRedirect="http://localhost:53551/" mode="On">
        <error statusCode="404" redirect="http://localhost:53551/"/>
        <error statusCode="500" redirect="http://localhost:53551/"/>
      </customErrors>
当所以Page2

。aspx没有找到,它被重定向到正确的URL,如下所示:

http://localhost: 53551/? aspxerrorpath =/page2.aspx

现在在页面http://localhost:53551/我需要知道从哪里来的请求?e.f.我需要知道完整的URL http://localhost:62203/但与重定向我只得到页面名称?aspxerrorpath=/page2.aspx

干杯哈利

要做到这一点,您需要在global.asaxApplication_Error上编写一些代码

void Application_Error(object sender, EventArgs e)
{
    HttpContext.Current.Request.Path ; // get's your url
}

在错误页面

获取最后一个错误,并有完整的消息和错误发生的url。

Exception ex = Server.GetLastError();

最新更新