Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我的控制器中有一些部分视图。问题是,如果用户输入 url: (www.mydomain.com/mycontroller/mypartialview),他们可以可视化我的部分视图。如何拒绝直接访问...并仅允许从基本视图使用部分视图?
谢谢!
添加 [ChildActionOnly] .. 像这样:
[ChildActionOnly] public PartialViewResult List(Model model) {... return PartialView(model); }
正如 Andras 所说,只有当你有一个控制器动作来返回它们时才会发生这种情况。我可以看到您可能已经有了这些,在这种情况下您应该将属性(过滤它们)添加为 [ChildActionOnly]