2. New Project

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.