WebSecurity を使用しているときに遭遇するすべての奇妙な例外に少しがっかりしています。また、OAuth との統合が不十分なため、見栄えがよくありません。概念を落として、ユーザー管理全体を手動で書くことを検討しています...
とにかく、私は WebSecurity を使用してユーザーとパスワードを管理しています。次に、アカウントを削除できる部分を実装しようとします。奇妙なことに、このメソッドは静的クラス WebSecurity にはありません。どうやら、SimpleMembershipProvider 経由でアカウントを削除する必要があるようです。
var provider = new SimpleMembershipProvider();
provider.DeleteAccount(username);
deleteAccount メソッドは、次のメッセージとともに無効な操作例外をスローします。
You must call the "WebSecurity.InitializeDatabaseConnection" method before you call
any other method of the "WebSecurity" class. This call should be placed in an
_AppStart.cshtml file in the root of your site.
_ViewStart に既にこれがあるので、それは奇妙です (そうでなければ、そもそもアカウントを作成できなかったでしょう)。
if (!WebSecurity.Initialized)
{
WebSecurity.InitializeDatabaseConnection(
"DefaultConnection",
"Users",
"UserId",
"UserName",
true);
}
今回は何が間違っていますか?