Blocking direct URL access to a controller returning a partialview?
If one where to have a controller named UsersCont开发者_Python百科roller 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?
Use ChildActionOnlyAttribute (http://haacked.com/archive/2009/11/18/aspnetmvc2-render-action.aspx)
[ChildActionOnly]
public ActionResult Menu() {
var menu = GetMenuFromSomewhere();
return PartialView(menu);
}
精彩评论