Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7865407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:04:42+00:00 2026-06-03T00:04:42+00:00

I am using the new MVC4 ASP.Net Web API system. I am calling my

  • 0

I am using the new MVC4 ASP.Net Web API system.

I am calling my API in a test project using WebClient. If I use GET or POST, it works fine. If I use anything else, I get Method Not Allowed. I am actually “faking” the method by injecting the following header. I am doing this because my end users will also have to do this due to the limitations of some firewalls.

I am calling the URL via IIS (i.e. not cassini) – e.g. http://localhost/MyAPI/api/Test

wc.Headers.Add("X-HTTP-Method", "PUT");

I tried adjusting the script mappings in IIS, but as there is no extension, I don’t know what I am meant to be adjusting!

Any ideas?
Regards
Nick

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T00:04:43+00:00Added an answer on June 3, 2026 at 12:04 am

    The X-HTTP-Method (or X-HTTP-Method-Override) header is not supported out of the box by Web API. You will need to create a custom DelegatingHandler (below implementation assumes that you are making your request with POST method as it should be):

    public class XHttpMethodDelegatingHandler : DelegatingHandler
    {
        private static readonly string[] _allowedHttpMethods = { "PUT", "DELETE" };
        private static readonly string _httpMethodHeader = "X-HTTP-Method";
    
        protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        {
            if (request.Method == HttpMethod.Post && request.Headers.Contains(_httpMethodHeader))
            {
                string httpMethod = request.Headers.GetValues(_httpMethodHeader).FirstOrDefault();
                if (_allowedHttpMethods.Contains(httpMethod, StringComparer.InvariantCultureIgnoreCase))
                request.Method = new HttpMethod(httpMethod);
            }
            return base.SendAsync(request, cancellationToken);
        }
    }
    

    Now you just need to register your DelegatingHandler in Global.asax:

    protected void Application_Start(object sender, EventArgs e)
    {
        GlobalConfiguration.Configuration.MessageHandlers.Add(new XHttpMethodDelegatingHandler());
        ...
    }
    

    This should do the trick.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm researching the new ASP.NET MVC4 Web API framework. I'm running Visual Studio 2011
I'm working on a new asp.net mvc4 project using Visual Studio 2011 beta and
I am starting a new project using MVC4 and would like to use dependency
We are starting a new ASP.NET MVC project. The web application will be used
I am using ASP.NET MVC4 with Entityframework. Does Entityframework supports new Time datatype of
I am considering building some services using the new Web API that's introduced in
I am attempting to write truly RESTful web services over HTTP using ASP.NET MVC
ASP.NET MVC4 Beta introduced an easy way to create OData endpoints using WebAPI. So
i already built some web applications using asp.net MVC 3 and they work well,
I created a simple Asp.net MVC 4 application I created the NUnit test project

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.