Chris
Chris

Reputation: 3201

Blocking direct URL access to a controller returning a partialview?

If one where to have a controller named UsersController with an action like:

public ActionResult ActiveUsers()
{
   IQueryable<TBL_USERS> recentUsers = repo.GetRecentUsers();
   Return PartialView(recentUsers);
}

And this is called via a Html.RenderAction() throughout the ap.

If a user were to navigate to Users/ActiveUsers directly in the address bar the partial view would be rendered in the browser.

Is it possible to block this?

Upvotes: 3

Views: 2290

Answers (1)

Kuvalda.Spb.Ru
Kuvalda.Spb.Ru

Reputation: 443

Use ChildActionOnlyAttribute (http://haacked.com/archive/2009/11/18/aspnetmvc2-render-action.aspx)

  [ChildActionOnly]
  public ActionResult Menu() {
    var menu = GetMenuFromSomewhere();
      return PartialView(menu);
  }

Upvotes: 7

Related Questions