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. 
Index
Welcome Guest - This is for all the anonymous user
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 :