从不同的控制器访问母版页超链接
我正在使用 ASP.NET 3.0 MVC 和会员提供程序。我必须修改我们使用会员相关代码获得的默认实现。我必须在母版页中移动注销超链接。最初此链接是不可见的,但一旦身份验证成功,我需要使其可见。此操作将从用于身份验证的控制器发生,我不确定如何从不同的控制器访问母版页中定义的超链接。有什么想法可以实现这一点并保持 MVC 设计的精神吗?
I am using ASP.NET 3.0 MVC with membership provider. I have to make modification to the default implementation we get with membership related code. I have to move LogOff Hyperlink in the master page. Initially this link is in-visible but once authentication is succesfful I need to make it visible. This action will happen from Controller for authentication and I am not sure how to access the hyperlink defined in a master page from a different controller. Any ideas how this could be achieved keeping the spirits of MVC design?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不确定为什么您需要进行修改,因为这似乎是默认行为,但通常您会使用部分视图来显示注销超链接。该部分视图可以运行一个操作,在此操作中,您将向视图发送一个模型,其中可能包含一个标志,表明用户当前是否已通过身份验证。或者,您可以直接在部分视图中检查Request.IsAuthenticated。
I'm not sure why you need to make a modification, as this seems to be the default behaviour, but typically you would use a partial view to display the log off hyperlink. This partial view can run an action, and in this action you would send a model to the view which could include a flag for if the user is currently authenticated. Alternatively, you can just check Request.IsAuthenticated in the partial view directly.
我不确定我是否理解。默认实现已经做到了这一点。无论您使用什么控制器,它都可以工作。原因是母版页使用了指定方法和控制器的部分页面。
I'm not sure I understand. The default implementation already does this. It works regardless of what controller you're using. The reason is that the master page uses a partial page that specifies the method and controller.
您可以在 AccountController 中创建另一个操作来确定是否需要显示注销链接。此操作有一部分针对 html。如果需要显示注销链接,请从母版页调用此新操作并签入该操作。
You could create another action in your AccountController to determine if the log off link needs to be displayed. This action has a partial for the html. Call this new action from the master page and check in that action if the log off link needs to be displayed.