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

In this post, I am going to implement Custom Forms authentication in ASP.NET MVC4 application. I often find that developers feel uncomfortable setting up Forms Authentication in their web applications. In ASP.NET default membership provider, Information about users and their roles stored in the predefined table and its not customizable which makes it very complicated to take full control of the database and forms authentication mechanism. I have split the entire application split into following parts for making things more simple and understandable. 
Login

[N:B: For test you can get username & password from here

X

User List

Full NameEmail IDUsernamePasswordRoles
Sourav Mondal[email protected]Sourav123456User,Admin
Rohan Roy[email protected]Rohan147852User
Jack Richard[email protected]Jack36985User
Brooke Smith[email protected]Brooke489834User
Byron Williams[email protected]Byron668587User
Dustin Jones[email protected]Dustin847340User
Easton Moore[email protected]Easton102609User
Perrin Taylor[email protected]Perrin120484User
Armon Jackson[email protected]Armon138360User
Novak Harris[email protected]Novak156235User
Kistna Martin[email protected]Kistna174110User
Mahari Thompson[email protected]Mahari191986User
Part 1- 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 :