If you want to password protect some pages on your MVC4 site using the Forms Authentication then it is best to to protect the whole site and then selectively allow Anonymous Access to the pages which are to be shown to every visitor.
Open the FilterConfig.VB file and add the line
filters.Add(New AuthorizeAttribute) in it
Once you run your application you would see that all the pages of your website are now protected, the users have to register before they can access.
Imports System.Web Imports System.Web.Mvc
Public Class FilterConfig Public Shared Sub RegisterGlobalFilters(ByVal filters As GlobalFilterCollection) filters.Add(New HandleErrorAttribute()) filters.Add(New AuthorizeAttribute) End Sub End Class
If you need to allow some pages for anonymous view then add the following decoration.
<AllowAnonymouse()> on each page which you want to open up for anonymous access.
<AllowAnonymous()> Function Index() As ActionResult ViewData("Message") = "Modify this template to jump-start your ASP.NET MVC application." Dim rep As New RepositoryRealEstate ViewBag.AgentCount = rep.GetAgentsCount ViewBag.ProperyCount = rep.GetPropertyCount ViewBag.VendorCount = rep.getvendorcount Return View() End Function