如果Action链接被禁用,如何使其无法通过MVC3中的url访问

发布于 2024-11-30 05:38:33 字数 616 浏览 2 评论 0原文

在我看来,我禁用或启用链接如下。即使视图中禁用了“受保人或所有者姓名更改”链接,我也可以通过“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心头的小情儿 2024-12-07 05:38:33

您永远不应该使用视图来处理访问控制或任何性质的业务逻辑。视图应该只具有表示层逻辑和标记。

也就是说,您可以在“NameChangeRequestController”中执行此操作 -> “Index”操作:

public ActionResult Index()
{
    if(!Model.CanCreateNameChangeRequest)
        RedirectToAction("Index","Home");
}

此外,这看起来很像基于角色的权限,在这种情况下,您应该将“[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:

public ActionResult Index()
{
    if(!Model.CanCreateNameChangeRequest)
        RedirectToAction("Index","Home");
}

Also, this looks a lot like Role based permissions, in which case you should use the "[Authorize]" attribute along with "IsInRole".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文