Part 2- How to implement custom Forms Authentication in ASP.NET MVC4 application

In this post, I am going to implement custom Membership Provider in Forms authentication in ASP.NET MVC4 application.

In the previous part of this series, we have implemented very simple and easy forms authentication. Now we will see how we can implement our custom Membership Provider.

In ASP.NET default membership provider API The information in the user and role table was predefined and it cannot be customized. It is very complicated to take full control of the database using ASP.NET default membership provider. So, here we will see how to implement our custom membership provider to take full control of the database and forms authentication mechanism (like validate user, create user, update user, delete user, change password and more).

I have split the entire application split into following parts for making things more simple and understandable.

Index
Welcome Guest - This is for all the anonymous user
Part 2- How to implement custom Forms Authentication in ASP.NET MVC4 application
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width" />
    <title>@ViewBag.Title</title>
    @Styles.Render("~/Content/css")
    @Scripts.Render("~/bundles/modernizr")
    <style>
        .menu {
            list-style:none;
            float:right;
        }
         .menu li {
            float:left;

        }
            .menu li a {
                padding:5px;
                margin-right:2px;
                background-color:#f3f3f3;
            }
    </style>
</head>
<body>
    <ul class="menu">
        <li>@Html.ActionLink("Home","Index","Home")</li>
        <li>@Html.ActionLink("My Profile","MyProfile","Home")</li>
        <li>
            @{
                if (Request.IsAuthenticated)
                {
                    using (Html.BeginForm("Logout","MyAccount", FormMethod.Post,new{ id = "logoutForm"}))
                    {
                        <a href="javascript:document.getElementById('logoutForm').submit()">Logout</a>
                    }
                }
                else
                {
                    @Html.ActionLink("Login","Login","MyAccount")
                }
            }
        </li>
    </ul>
    <div style="height:1px;clear:both"></div>
    @RenderBody()

    @Scripts.Render("~/bundles/jquery")
    @RenderSection("scripts", required: false)
</body>
</html>

Posted By :