简体   繁体   English

隐藏@ Url.Action中的参数

[英]Hide parameters from @Url.Action

I have this code 我有这个代码

<a href="@Url.Action(" Edicao ", "EdicaoListaVerificacao ", new { idFormulario = m.Id })" title="Editar" class="glyphicon glyphicon-pencil" aria-hidden="true" />

Where 'Edit' is my action and 'FunctionEdit' is my Controller. “编辑”是我的操作,“功能编辑”是我的控制器。 My action needs a parameter and I passed it building a 'instance'. 我的动作需要一个参数,并通过它建立了一个“实例”。 How the property needs. 物业的需求。 The problem is that the URL can be altered and the user can access things that they can't. 问题在于URL可以更改,并且用户可以访问他们不能访问的内容。

You can never hide your URLs - nor should you. 您永远都不会隐藏自己的网址-也应该如此。 You should verify, instead, inside the Edicao action method that the user has permission to view the Formulario with the specified Id . 您应该在Edicao操作方法内验证用户是否有权查看具有指定IDFormulario

In all web applications, you have to assume that the URLs users try to retrieve can be absolutely anything - and that some users will attempt to edit URLs to get at hidden content. 在所有Web应用程序中,您必须假定用户尝试检索的URL绝对可以是任何东西-并且某些用户将尝试编辑URL以获取隐藏的内容。 ASP.NET has built-in authentication and authorization mechanisms that you should use. ASP.NET具有应使用的内置身份验证和授权机制。

If you're just looking for a simple way to make a URL that's impossible to guess , without forcing users to log on, you have to use something more complicated than a numeric ID, like a GUID. 如果您只是在寻找一种简单的方法来制作无法猜测的URL,而又不强迫用户登录,则必须使用比数字ID更复杂的东西,例如GUID。

And if at any point you are tempted by roll-your-own solutions such as URL referrer checking or verifying cookies, remember that easier-to-use solutions are most likely built into ASP.NET already. 并且,如果在任何时候您都对自己的解决方案(如URL引荐来源网址检查或验证Cookie)感兴趣,请记住,易于使用的解决方案很可能已经内置在ASP.NET中。

That's it! 而已! Thank you, guys. 感谢大伙们。 I found a way to implement a check in my action. 我找到了一种在操作中实施检查的方法。 With Request.UrlReferrer . 使用Request.UrlReferrer

 public ActionResult Edicao(int idFormulario)
        {
            Uri url = Request.UrlReferrer;

            if (url != null)
            {

               DO ALL THINGS YOU HAVE TO

            }
            else
            {
                RETURN TO INDEX
            }

        }

The Request.UrlReferrer returns me the URL if it comes from my request. 如果来自我的请求,则Request.UrlReferrer会向我返回该URL。 If not returns null . 如果不是,则返回null Than I just build an if block ;). 比我只是建立一个if块 ;)。 Thank you guys! 感谢大伙们!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM