1. New Project
Internet applications, such as ASP. NET MVC4 Web application (Select Razor view engine, and create test units here)
2. Replace the database
Direct Click to run the Discovery Project can be run, and can register login, here it uses the VS comes with the database, because it does not know much, first changed it again, using the regular database
1. Modify the Web. config, modify the connectionStrings node to
<add name= "Connstring-sun" connectionstring= "server=.; Integrated Security=true;database=sun "providername=" System.Data.SqlClient "/>
2. Modify the Models\accountmodels, modify the Userscontext constructor as: Base ("Connstring-sun")
3. Change the Filters\initializesimplemembershipattribute, websecurity.initializedatabaseconnection the first parameter to " Connstring-sun "
At this point, the database has been changed to a local mss2012 database, where EF's code-first is used
3. User Login
Login is always wanted, the login function with the first do not move him, first do a login filter;
Use Filter here, refer to: http://www.cnblogs.com/shanyou/archive/2010/03/27/1698639.html
1. Create a new Authenattribute under filters
Public class Authenattribute:actionfilterattribute { publicoverridevoid onactionexecuting (actionexecutingcontext Filtercontext) { ifreturn; New Redirectresult ("/account/login?redirecturl=" + FILTERCONTEXT.HTTPCONTEXT.REQUEST.RAWURL); } }
2. Add a property to a Controller or Action
[Authen] public ActionResult About () { return View (); }
2. New Project