How to add ASP.NET Membership Provider in a Empty MVC 4 Project Template?

后端 未结 4 770
逝去的感伤
逝去的感伤 2020-12-01 02:36

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

相关标签:
4条回答
  • 2020-12-01 02:39

    Simple Membership in ASP NET MVC 5 Web Applications

    https://www.youtube.com/watch?v=BsKcVbsMn6w

    Implementing User Authentication in a project once it is developed is really difficult. In this video I have demonstrated how you can effectively utilize Microsoft Simple Membership feature in those projects in which you haven't implemented the Authentication from the very start. With the help of this you can implement the authentication feature at any stage of the project.

    0 讨论(0)
  • 2020-12-01 02:48

    Installing it

    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

        • Microsoft.AspNet.WebPages.Data
      • DotNetOpenAuth.AspNet

        • DotNetOpenAuth.OpenId.RelyingParty

          • DotNetOpenAuth.OpenId.Core

            • DotNetOpenAuth.Core

              • CodeContracts.Unofficial
        • DotNetOpenAuth.OAuth.Consumer

          • DotNetOpenAuth.OAuth.Core

            • DotNetOpenAuth.Core

              • CodeContracts.Unofficial

    Add a reference to

    • System.Transactions

    Testing it

    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

    enter image description here

    Registering

    enter image description here

    Logged IN

    enter image description here

    0 讨论(0)
  • 2020-12-01 02:48

    If you want to use Universal Providers as opposed to Simple Membership that's included in MVC 4 Internet template, you can create a new MVC 4 project using Mobile template and copy Account controller + views and also update web.config with correct connectionString and Forms Auth section and you should be good to go.

    0 讨论(0)
  • 2020-12-01 02:59

    Check out SimpleMembership, Membership Providers, Universal Providers and the new ASP.NET 4.5 Web Forms and ASP.NET MVC 4 templates to get an info about what you need to set SimpleMembership inside empty template.

    You my also want to check out very nice posts from Scott Allen:

    Perils of the MVC4 AccountController

    Build Your Own Membership System For ASP.NET MVC - Part I

    and

    Build Your Own Membership System For ASP.NET MVC - Part II

    0 讨论(0)
提交回复
热议问题