为 ASP.NET MVC 中的所有站外链接强制使用中间页面?
此页面列出了将用户重定向离开您的主网站时需要注意的一些安全问题。
如何连接 ASP.NET MVC“管道”来检测何时创建超链接,并更改它以使其转到重定向页面,例如 https://host.com/redirect.aspx? http://yourlink.com
This page lists a number of security issues to be aware of when redirecting a user off your primary website.
How can I hook into the ASP.NET MVC "pipeline" to detect when a hyperlink is being created, and alter it so that it goes to a redirection page such as https://host.com/redirect.aspx?http://yourlink.com
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没有任何简单的方法可以直接修改视图代码创建的所有链接,因此这实际上取决于您愿意做多少工作。
假设您的用户启用了 javascript,最简单的方法可能是使用 jQuery 扫描页面中的链接并根据需要进行修改。这样,您的其他代码就不必更改。
http://jquery-howto.blogspot .com/2009/06/find-select-all-external-links-with.html
另一种方法是制定始终通过调用特定扩展方法来创建外部链接的策略:
这引入了更多维护开销,但至少它将重定向代码本身合并到一个地方,如果您将来需要的话,您可以轻松地更改它。
There isn't any easy way to directly modify all links created by your View code, so it really depends on how much work you're willing to do.
Assuming your users have javascript enabled, the easiest way would probably be to use jQuery to scan your page for links and modify them as appropriate. That way, none of your other code has to change.
http://jquery-howto.blogspot.com/2009/06/find-select-all-external-links-with.html
Another approach would be to have a policy of always creating external links by invoking a specific extension method:
This introduces more maintenance overhead, but at least it consolidates the redirect code itself to one place where you could easily change it if you need to at some point in the future.