ASP.NET 母版页 Page_Load Override
我的网站有一个母版页,用于设计网站其余部分的样式并进行用户身份验证。这工作得很好,只是我有一个页面想要保留母版的样式,但不进行身份验证,因为这是一个页面,告诉用户他们没有经过身份验证。如何从这一页重写 MasterPage 的 Page_Load 方法?关于如何在不从主站移动身份验证的情况下无法在这一页上进行身份验证的任何其他想法?
I have a Master page for my site that is used for styling the rest of the site and doing user authentication. This works fine except that I have one page that I would like to retain the styling from the master but not do the authentication since this is the page that tells the user that they aren't authenticated. How could I override the MasterPage's Page_Load method from this one page? Any other thoughts on how I could not authenticate on this one page without moving authentication from the master?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
也许可以在 Request.Current.Url 中的某个位置检查母版页中的当前页面名称 (Whatever.aspx) 并跳过对其进行身份验证。
Maybe check in your master page somewhere in Request.Current.Url for the current page name (Whatever.aspx) and skip authentication for it.
您可以在母版页上创建一个默认为 true 的属性,这意味着应该进行身份验证。然后,您可以在单页的初始化逻辑内将该属性设置为 false。当母版页尝试进行身份验证时,它应该首先检查此属性的状态。
有关如何与此类母版页进行通信的示例,请查看 此内容的抽象交互部分文章。
You can create a property on your master page that defaults to true, meaning that authenitcation should happen. You can then set that property inside of the initialization logic for the single page to false. When the master page tries to do authentication, it should first check for the state of this property.
For an example of how to communicate with a master page like this, take a look at the Abstract Interaction section of this article.
使用Request.Current.Url 检测页面是一个很好的解决方案。
另一种方法是使用 LoginView它具有 LoggedInTemplate、AnonymousTemplate 和用于内容查看的角色支持。
Detecting page by using Request.Current.Url is a good solution.
Another way is to use LoginView which has LoggedInTemplate, AnonymousTemplate and roles support for content viewing.