I've implemented a Simple Membership in my ASP.NET MVC4 application. But now I need to implemente the creation the users and verify the login in it.
So I started to copy some pieces of code of my recent project to this. By example, this is the part where crashes
WebSecurity.InitializeDatabaseConnection("SimpleMembershipConnection",
"UserProfile", "UserId", "UserName", autoCreateTables: true);
bool val = WebSecurity.Login("1010", "pass"); // here throws the exception
The error says:
Object reference not set to an instance of an object. Parameter name: httpContext.
Also, I just import some libraries as WebMatrix.WebData, WebMatrix.Data, and System.Web
This is my entire 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>
How can I fix the exception, about not getting null in HttpContext?