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

查看:42
本文介绍了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天全站免登陆