MVCのデフォルトメンバーシップからユーザーを削除しようとしていますが、渡されるパラメーターは常にnullです。[HttpDelete]
属性を使用しまし[FromBody]
たが、「500サーバー内部エラー」が発生します。以下は私のコードです
// 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);
}
これは、「Delete」動詞を使用した私の呼び出しメソッドです。
http://localhost:3325/api/Del/haris2
ルーティング用にこのwebapiクラスを作成しました。同じコントローラーに引数のないGetメソッドがあります。その動作は問題ありません。
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 }
);
}
}
}