阻止直接URL访问返回部分视图的控制器? [英] Blocking direct URL access to a controller returning a partialview?
本文介绍了阻止直接URL访问返回部分视图的控制器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果要在其中放置一个名为UsersController的控制器,并执行以下操作:
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);
}
这在整个ap中通过Html.RenderAction()
调用.
And this is called via a Html.RenderAction()
throughout the ap.
如果用户要直接在地址栏中导航到"Users/ActiveUsers",则部分视图将在浏览器中呈现.
If a user were to navigate to Users/ActiveUsers directly in the address bar the partial view would be rendered in the browser.
有可能阻止吗?
推荐答案
使用ChildActionOnlyAttribute( http://haacked.com/archive/2009/11/18/aspnetmvc2-render-action.aspx )
Use ChildActionOnlyAttribute (http://haacked.com/archive/2009/11/18/aspnetmvc2-render-action.aspx)
[ChildActionOnly]
public ActionResult Menu() {
var menu = GetMenuFromSomewhere();
return PartialView(menu);
}
这篇关于阻止直接URL访问返回部分视图的控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文