I'm trying to delete a user from Default Membership of MVC but the passing parameters is always null. I've used [HttpDelete] attribute and [FromBody] but it gives "500 Server internal error". below is my code
// Delete api/Del/user name
public HttpResponseMessage DeleteUser(string user)
{
try
{
System.Web.Security.Membership.DeleteUser(user);
}
catch (Exception)
{
return Request.CreateResponse(HttpStatusCode.NotFound);
}
return Request.CreateResponse(HttpStatusCode.OK);
}
This is my calling method with "Delete" verb.
http://localhost:3325/api/Del/haris2
I've created this webapi class for routing. I have a Get Method in Same controller with no arguments. Its working is fine.
WebApiConfig.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
namespace DatabaseService_WebAPI.App_Start
{
public class WebApiConfig
{
public static void Configure(HttpConfiguration config)
{
// Filters
config.Filters.Add(new QueryableAttribute());
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
config.Routes.MapHttpRoute(
name: "DefaultApiwithAction",
routeTemplate: "api/{controller}/{action}",
defaults: new { id = RouteParameter.Optional }
);
}
}
}
[HttpDelete]attribute at the top of yourDeletemethod (not sure why adding that would be throwing a server error). Are you actually posting usingDELETEas the verb?haris2is an id or an action?) And I'm presuming theDeleteUseraction is in theDelControllercontroller?