ASP.NET page POST only access

久未见 提交于 2019-12-02 13:27:01

问题


I was wondering if it is possible to restrict access to an ASPX page to http POST request method only? This restricted page will be used to render some complex content. I want to use it for ajax calls which will return that content into a div on another page. Is it possible to disable GET requests so that users won't be able to access it via URL in their browser by accident?


回答1:


You can't prevent user from making a GET request. You can choose on server that you won't serve those. For example like:

  if (!string.Equals(Request.HttpMethod, "POST"))
  {
      Response.StatusCode = 405;
      Response.End();
  }

This can be implemented in Page_Load event or even in HttpModule (if you need it for more pages, etc).



来源:https://stackoverflow.com/questions/32326619/asp-net-page-post-only-access

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!