ASP.NET 页面 POST 只能访问 [英] ASP.NET page POST only access

查看:31
本文介绍了ASP.NET 页面 POST 只能访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以将对 ASPX 页面的访问限制为仅使用 http POST 请求方法?此受限页面将用于呈现一些复杂的内容.我想将它用于 ajax 调用,它将将该内容返回到另一个页面上的 div 中.是否可以禁用 GET 请求,以便用户无法通过浏览器中的 URL 意外访问它?

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?

推荐答案

您无法阻止用户发出 GET 请求.您可以在服务器上选择不提供这些服务.例如像:

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();
  }

这可以在 Page_Load 事件中实现,甚至可以在 HttpModule 中实现(如果您需要更多页面等).

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

这篇关于ASP.NET 页面 POST 只能访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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