ASP.NET MVC4 アプリケーションにシンプル メンバーシップを実装しました。しかし今、ユーザーの作成を実装し、ログインを確認する必要があります。
そこで、最近のプロジェクトのコードの一部をこれにコピーし始めました。例によって、これはクラッシュする部分です
WebSecurity.InitializeDatabaseConnection("SimpleMembershipConnection",
"UserProfile", "UserId", "UserName", autoCreateTables: true);
bool val = WebSecurity.Login("1010", "pass"); // here throws the exception
エラーは言う:
オブジェクト参照がオブジェクト インスタンスに設定されていません。パラメータ名: httpContext.
また、いくつかのライブラリを WebMatrix.WebData、WebMatrix.Data、および System.Web としてインポートするだけです。
これは私のapp.config全体です
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<connectionStrings>
...
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
</entityFramework>
<roleManager enabled="true" defaultProvider="simple">
<providers>
<clear />
<add name="simple" type="WebMatrix.WebData.SimpleRoleProvider, WebMatrix.WebData" />
</providers>
</roleManager>
<membership defaultProvider="simple">
<providers>
<clear />
<add name="simple" type="WebMatrix.WebData.SimpleMembershipProvider, WebMatrix.WebData" />
</providers>
</membership>
HttpContext で null を取得しないという例外を修正するにはどうすればよいですか?