作为标题,我正在尝试在Asp.net 4.6框架中实现AntiForgery令牌。我有一个Site.Master页面,正在研究本文以适应我的网站How To Fix Cross-Site Request Forgery (CSRF) using Microsoft .Net ViewStateUserKey and Double Submit Cookie
现在我已经从c#转换为vb.net,并将代码放在我的母版页中。
由编译器向我指出
Page.PreLoad += AddressOf master_Page_PreLoad
是一个事件,我不能直接声明。
无论如何我都不知道这是解决问题的正确方法还是存在另一种遵循的方法。
已解决。使用
AddHandler Page.PreLoad, AddressOf master_Page_PreLoad
代替
Page.PreLoad += AddressOf master_Page_PreLoad
关于我必须使用的webmethod中的目标“在ASP.NET 4.6 WebForm上实现AntiForgery令牌”的其他内容
HttpContext.Current.Session(“ CookieName”)来验证在Page_Init上生成的令牌,因为在webmethos中,您不能使用ViewState。
要在Web方法中使用Sessione,必须在Web方法的声明中将EnableSession定义为:>
<WebMethod(EnableSession:=True), ScriptMethod(ResponseFormat:=ResponseFormat.Json, UseHttpGet:=False)> _
Public Function GetFunction(myjson As String) As String.....