我写的代码,以防止用户身份验证在我的GET方法像下面如何防止用户在MVC Razor注销后按返回按钮时的身份验证?
if (!string.IsNullOrEmpty(Session["UserName"].ToString()))
{
MyConnection mycon = new MyConnection();
string str = "";
int res = 0;
if (Request.QueryString.ToString().Contains("ID1"))
{
str = "Delete from PostTable where PostID=" + Request.QueryString["ID1"];
res = mycon.IODPost(str);
}
return View(AllPostList());
}
else
{
return RedirectToAction("Home", "Home");
}
,但是当我在浏览器中按后退按钮signout后,页面回发到前一页不能完成。那么我应该怎么做才能防止这种情况呢?
您有一个SQL注入漏洞。 – SLaks
不要从GET请求中删除东西。 – SLaks
也不要使用会话进行身份验证(查看会话劫持),并看看使用AuthorizeAttribute或类似的,或者你会有这个地方 – RichardW1001