加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – 重定向到一个页面,其endResponse为true VS CompleteR

发布时间:2020-12-16 07:17:14 所属栏目:asp.Net 来源:网络整理
导读:基于 this questions and the answers there,我想问一下重定向的正确方法是什么. 使用Redirect(url,endResponse)的默认方式是抛出ThreadAbortException,因为调用endResponse = true调用End()方法,因此,如果你在try / catch块中使用它,这个exception shown th
基于 this questions and the answers there,我想问一下重定向的正确方法是什么.

使用Redirect(url,endResponse)的默认方式是抛出ThreadAbortException,因为调用endResponse = true调用End()方法,因此,如果你在try / catch块中使用它,这个exception shown there可以假设为错误,但实际上用户尝试通过停止页面处理的其余部分来重定向到页面.

其他可能的方法是使用endResponse = false调用Redirect(url,endResponse),然后使用HttpContext.Current.ApplicationInstance.CompleteRequest();通过使用它你不会得到任何例外.

所以问题是什么更好用,为什么.

解决方法

您必须始终使用endRespose = true调用重定向,否则任何黑客都可以通过简单地保留重定向来查看页面上的内容.

为了证明我使用Firefox的NoRedirect插件来保存重定向.然后我测试了两个案例,结果如下:

我有一个包含该文本的简单页面

<form id="form1" runat="server">
<div>
I am making a redirect - you must NOT see this text.
</div>
</form>

然后在页面加载尝试使用两种情况进行重定向:

第一种情况,使用Complete Request();

try
    {
        // redirect with false that did not throw exception
        Response.Redirect("SecondEndPage.aspx",false);
        // complete the Request
        HttpContext.Current.ApplicationInstance.CompleteRequest();
    }
    catch (Exception x)
    {

    }

繁荣,你可以在页面内看到什么!

第二种情况

try
{
    // this is throw the ThreadAbortException exception
    Response.Redirect("SecondEndPage.aspx",true);
}
catch (ThreadAbortException)
{
    // ignore it because we know that come from the redirect
}
catch (Exception x)
{

}

现在没有显示.

因此,如果您不喜欢黑客在您的页面上看到什么,您必须使用endResponse将其调用为true并停止进行其他处理 – 例如从函数返回而不是继续.

例如,如果您检查用户是否已通过身份验证,他可以看到该页面,或者如果不是,则必须重定向到登录,如果您尝试将endResponse重定向到false,则甚至在登录中,然后持有黑客可以看到的重定向 – 什么你相信不能因为你使用重定向.

我的基本观点是,如果您不停止将数据发送回浏览器,则显示存在的安全线程.重定向是浏览器的标题和指令,但同时您需要停止发送任何其他数据,您必须停止发送页面的任何其他部分.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读