Ari*_*tos 5 asp.net security redirect
基于这些问题和那里的答案,我想问一下重定向的正确方法是什么.
使用Redirect(url,endResponse)的默认方式是抛出ThreadAbortException因为endResponse=true调用End()方法而调用,因此,如果在try/catch块中使用它,那么此异常显示在那里并且可以假定为错误,但实际上用户尝试通过停止页面处理的其余部分来重定向到页面.
其他可能的方法是Redirect(url, endResponse)使用endResponse=false以下方法调用with ,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>
Run Code Online (Sandbox Code Playgroud)
然后在页面加载尝试使用两种情况进行重定向:
第一种情况,使用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)
{
}
Run Code Online (Sandbox Code Playgroud)
繁荣,你可以在页面内看到什么!

第二种情况
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)
{
}
Run Code Online (Sandbox Code Playgroud)
现在没有显示.

因此,如果您不喜欢黑客在您的页面上看到什么,您必须使用endResponse将其调用为true并停止进行其他处理 - 例如从函数返回而不是继续.
例如,如果您检查用户是否已通过身份验证,他可以看到该页面,或者如果不是,则必须重定向到登录,如果您尝试将endResponse重定向到false,则甚至在登录中,然后持有黑客可以看到的重定向 - 什么你相信不能因为你使用重定向.
我的基本观点是,如果您不停止将数据发送回浏览器,则显示存在的安全线程.重定向是浏览器的标题和指令,但同时您需要停止发送任何其他数据,您必须停止发送页面的任何其他部分.
| 归档时间: |
|
| 查看次数: |
10830 次 |
| 最近记录: |