3

I was trying to use "PUT" in my controller like

public class HomeController : Controller
    {
        [HttpPut]
        public ContentResult Test()
        {
            return Content("hi");
        }
    }

but I can't access it. I thought it was my code but after trying fiddler and getting the same error(404).

I think something else is up. I am just using iis express and mvc 5.

Before I never used HttpPut but been doing webapi lately so that's why I tried to do it in mvc 5 controller but I am not sure if in this case it bring me anything(especially with extra setup is needed as it seems like it is need)

enter image description here

Post request works

enter image description here

5
  • Are you making an HTTP PUT request? If so, how are you making it? I've got [HttpPut] being used in production so I know it works. Commented Apr 22, 2014 at 21:37
  • well I am using x-editable with "PUT" type and it did not work, then I used fiddler 2 with "PUT" and same thing get 404. Commented Apr 22, 2014 at 21:38
  • Can you show the full controller class and what the HTTP request that you're making looks like? Commented Apr 22, 2014 at 21:39
  • @chobo2 Is this action in an MVC or Web API controller? What is the controller's name? What is the URL path you're requesting? Commented Apr 22, 2014 at 21:41
  • That is an MVC Controller not a WebApi Controller Commented Apr 22, 2014 at 21:51

2 Answers 2

2

Another possibility is to update the ExtensionlessUrlHandler-Integrated-4.0.

<system.webServer>
    <handlers>
        <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
        <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*"   type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
</system.webServer>

This solution can be found on: Attribute routing with http PUT method constraint

Sign up to request clarification or add additional context in comments.

Comments

1

There are several possibilities for this failure. One is security, meaning that PUT header is being blocked:

Does your web server allow PUT headers? Try this:

...    
 <security>
            <requestFiltering>
                <verbs>
                    <add verb="PUT" allowed="true" />
                </verbs>
            </requestFiltering>
        </security>
    </system.webServer>

The other possibility is that your test is being subject to CORS (Cross Origin Resource Sharing) and you may need to enable it in MVC. I have personally not done this MVC but only WebApi. I hope this link can help you:

http://www.c-sharpcorner.com/Blogs/11609/how-to-enable-cross-origin-resource-sharing-in-mvc.aspx

2 Comments

Correct, Can you not use "PUt" with a regular controller, it is just a standard http request.
Well it is being ran locally through VS 2013 but I can try adding that to my web.config

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.