[英]Link security trimming in asp.net mvc
I would like to show some links only to authenticated users in an asp.net mvc web application.我想在 asp.net mvc web 应用程序中仅向经过身份验证的用户显示一些链接。
<a href="/Account/ChangePassword">Change password</a>
and only show the link to users who are logged in.并且只显示登录用户的链接。
What is the simplest way to do that?最简单的方法是什么? I would like something as simple as security trimming of the web.sitemap that I have tried with asp.net web forms. (Can that be used with mvc? Or is it only for web forms?)我想要像 web.sitemap 的安全修整一样简单的东西,我已经尝试过 asp.net web forms。(它可以与 mvc 一起使用吗?还是仅适用于 web forms?)
You could build a custom SiteMapProvider like this one: 你可以构建一个像这样的自定义SiteMapProvider:
Building an ASP.NET MVC sitemap provider with security trimming 使用安全修整构建ASP.NET MVC站点地图提供程序
The following should work. 以下应该有效。 You'll also need to do something similar in the controller action for this in case the user inputs the URL by hand in their browser. 如果用户在浏览器中手动输入URL,您还需要在控制器操作中执行类似的操作。 Or, as you say, you could restrict access to the action in the web.config. 或者,正如您所说,您可以限制对web.config中操作的访问。
<% if (HttpContext.Current.Request.IsAuthenticated) { %>
<a href="/Account/ChangePassword">Change password</a>
<% } %>
show change password link 显示更改密码链接
show login link 显示登录链接
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.