如果Action链接被禁用,如何使其无法通过MVC3中的url访问
在我看来,我禁用或启用链接如下。即使视图中禁用了“受保人或所有者姓名更改”链接,我也可以通过“http://localhost:0000/NameChangeRequest?contract=111111”等 url 访问它,但这种情况不应该发生。谁能帮我解决这个问题吗?
@if (Model.CanCreateNameChangeRequest)
{
@Html.ActionLink("Insured or Owner Name Change", "Index", "NameChangeRequest", new { @contract = Model.ContractNumber }, new { @class = "requestLink" });
}
else
{
<span class="requestLinkDisabled">Insured or Owner Name Change</span>
}
In my view I disable or enable links as below. Even if the link "Insured or Owner Name Change" is disabled in the view I am able to access it through the url like "http://localhost:0000/NameChangeRequest?contract=111111" which should not be happening. Can anyone help me on this?
@if (Model.CanCreateNameChangeRequest)
{
@Html.ActionLink("Insured or Owner Name Change", "Index", "NameChangeRequest", new { @contract = Model.ContractNumber }, new { @class = "requestLink" });
}
else
{
<span class="requestLinkDisabled">Insured or Owner Name Change</span>
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您永远不应该使用视图来处理访问控制或任何性质的业务逻辑。视图应该只具有表示层逻辑和标记。
也就是说,您可以在“NameChangeRequestController”中执行此操作 -> “Index”操作:
此外,这看起来很像基于角色的权限,在这种情况下,您应该将“[Authorize]”属性与“IsInRole”一起使用。
You should never use Views to handle access control or any nature of business logic really. The View should only have presentation layer logic and markup.
That said, you can do this in the "NameChangeRequestController" -> "Index" action:
Also, this looks a lot like Role based permissions, in which case you should use the "[Authorize]" attribute along with "IsInRole".