ASP.NET page POST only access

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?

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 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;

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

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply