我正在开发一个httphandler来处理Web表单(而不是MVC)中的一些请求。
如何实现反跨站脚本(如MVC中的防伪)?
我想了解一下MVC中的防伪机制。
发布于 2010-07-20 23:36:33
如果可以访问该页,则可以使用该页的ViewStateUserKey属性。下面是一个如何在页面中执行此操作的示例,但您将会领会其中的含义:
protected void Page_Init(object sender, EventArgs e)
{
// Validate whether ViewState contains the MAC fingerprint
// Without a fingerprint, it's impossible to prevent CSRF.
if (!this.Page.EnableViewStateMac)
{
throw new InvalidOperationException(
"The page does NOT have the MAC enabled and the view" +
"state is therefore vulnerable to tampering.");
}
this.ViewStateUserKey = this.Session.SessionID;
}
虽然ViewStateUserKey相当安全,但也有一些不足之处。您可以阅读有关该here的更多信息。
https://stackoverflow.com/questions/3291414
复制相似问题