I have created delete,put method using WebAPI. While calling the method from postman i am getting the method not allowed. I have done R&D and applied the changes but no luck. Please help me on this.
//[System.Web.Http.AcceptVerbs("GET", "POST","DELETE")]
//[System.Web.Http.HttpDelete]
public void Delete(int id)
{
using (EmployeeDBEntities entities = new EmployeeDBEntities())
{
entities.emps.Remove(entities.emps.FirstOrDefault(e=>id==e.id));
entities.SaveChanges();
Most likely your PostMan configuration is incorrectly. I built a test with the default values controllers and PostMan works perfectly.
Get in mind, if you are trying to configure one action for GET, POST, and DELETE then you're not following standards and should expect the action will not work properly.
None
0 Points
3 Posts
405 method not allowed(postman)
Mar 28, 2020 05:16 PM|sridhar1975|LINK
Hi All,
I have created delete,put method using WebAPI. While calling the method from postman i am getting the method not allowed. I have done R&D and applied the changes but no luck. Please help me on this.
//[System.Web.Http.AcceptVerbs("GET", "POST","DELETE")]
//[System.Web.Http.HttpDelete]
public void Delete(int id)
{
using (EmployeeDBEntities entities = new EmployeeDBEntities())
{
entities.emps.Remove(entities.emps.FirstOrDefault(e=>id==e.id));
entities.SaveChanges();
}
}
settings in webconfig
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true">
<remove name="WebDAVModule" />
</modules>
<handlers>
<remove name="WebDAV" />
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>
All-Star
53041 Points
23611 Posts
Re: 405 method not allowed(postman)
Mar 28, 2020 06:25 PM|mgebhard|LINK
Most likely your PostMan configuration is incorrectly. I built a test with the default values controllers and PostMan works perfectly.
Get in mind, if you are trying to configure one action for GET, POST, and DELETE then you're not following standards and should expect the action will not work properly.
https://docs.microsoft.com/en-us/aspnet/web-api/overview/getting-started-with-aspnet-web-api/tutorial-your-first-web-api
All-Star
48510 Points
18072 Posts
Re: 405 method not allowed(postman)
Mar 28, 2020 06:37 PM|PatriceSc|LINK
Hi,
This is ASP.NET 4.x? What if you remove WebDAV al;so from system.web?
You may want to see with those in charge but if webdav is not usefull you could likely remove it enitrely at the IIS level.