preventing cross-site request forgery (csrf) attacks in asp.net web forms

后端 未结 4 1143
野性不改
野性不改 2020-12-04 14:59

I have created an ASP.Net Web Forms application using Visual Studio 2013 and I am using .NET Framework 4.5. I want to make sure my site is secure from Cross-Site Request For

4条回答
  •  抹茶落季
    2020-12-04 15:23

    You could use below piece of code, which will check the request where it is coming from

    if ((context.Request.UrlReferrer == null || context.Request.Url.Host != context.Request.UrlReferrer.Host)) 
        {
            context.Response.Redirect("~/error.aspx", false);
        }
    

    It works great for me!!!

提交回复
热议问题