I am new in ASP.NET MVC4. I am creating a Empty MVC4 Project Template and trying to add ASP.NET Membership Provider into it but i am not understanding how can I do it. I am searching in Google but all demos are using Internet Application project template.
I know this question is not good but i am already spend two days for it.
Please give a some advice or tutorial for this purpose.
Update
According to Nesim Razon`s advice i copy and paste forms authentication sections to my empty project from a MVC4 Web Application (Internet Application template). But now i get an exception
To call this method, the "Membership.Provider" property must be an instance of "ExtendedMembershipProvider".
[InitializeSimpleMembership] public class HomeController : Controller { public ActionResult Index() { WebSecurity.CreateUserAndAccount("Name", "Password"); // Exception is thrown from there. return View(); } }
I am also added the following directive in the Web.config file:
<add key="enableSimpleMembership" value="true" />
Adding the AccountController and Views Create a new ASP.NET MVC application using the full ASP.NET MVC 3 Web Application template and copy the following files into the same directories in our project: Copy AccountController. cs in the Controllers directory. Copy AccountModels in the Models directory.
The ASP.NET membership provider is a feature that enables ASP.NET developers to create Web sites that allow users to create unique user name and password combinations. With this facility, any user can establish an account with the site, and sign in for exclusive access to the site and its services.
You need to add the following Nuget Packages:
EntityFramework
Microsoft.AspNet.WebPages.OAuth
Note: This package will install all the required dependencies automatically for you. This is a detailed list of all nuget packages installed:
Microsoft.AspNet.WebPages.WebData
DotNetOpenAuth.AspNet
DotNetOpenAuth.OpenId.RelyingParty
DotNetOpenAuth.OpenId.Core
DotNetOpenAuth.Core
DotNetOpenAuth.OAuth.Consumer
DotNetOpenAuth.OAuth.Core
DotNetOpenAuth.Core
Add a reference to
Now in order to test it, add the following to the web.config file (Under system.web
):
<authentication mode="Forms"> <forms loginUrl="~/Account/Login" timeout="2880" /> </authentication>
Add the following connection string
<connectionStrings> <add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-UnitTestQueries.UI-20121105001038;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-UnitTestQueries.UI-20121105001038.mdf" providerName="System.Data.SqlClient" /> </connectionStrings>
And what I did was to copy the controllers, models, filters and views from the Internet template and just modify things like the namespace and so on until you get it up and running
This is the result (without styles)
Before login
Registering
Logged IN
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With