在Asp.net形式防伪实施 [英] AntiForgery implementation in Asp.net Forms

查看:250
本文介绍了在Asp.net形式防伪实施的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个HttpHandler来处理Web窗体(不在MVC)的一些要求。结果
我怎么能实现防跨站脚本(如在MVC防伪)?结果
我想了解一下MVC的防伪机制MRE。

I am developing an httphandler to process some requests in Web Forms (NOT in MVC).
How could I implement Anti Cross Site Scripting (like antiforgery in MVC)?
I want to know mre about the antiforgery mechanism in MVC.

推荐答案

如果您可以访问该页面,则可以使用的 ViewStateUserKey 页面的财产。下面是如何从页面内做一个这样的例子,但你会得到的想法:

If you can access the Page, you can use the ViewStateUserKey property of the Page. Here is an example of how to do this from within the page, but you will get the idea:

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是pretty安全的,也有一些短自带这一点。你可以阅读更多有关这里

这篇关于在Asp.net形式防伪实施的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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