当请求重定向时,如何读取目标 URL?
我使用的是 MasterPage
,整个页面上有一个动态菜单栏。如果用户请求重定向回登录(主页)页面,我不想将其注销,但我确实想隐藏菜单栏。目前我正在使用用户是否经过身份验证来控制菜单栏是否可见。
基本上,我想在登录页面上始终隐藏菜单栏。菜单在页面本身之前呈现,因此我需要能够读取重定向请求以查看登录页面是否是目的地。我尝试了 Response.RedirectLocation 字段,但它似乎为空。
如何确定重定向请求是什么?
I am using a MasterPage
with a dynamic menu bar across the page. If the user has requested a redirect back to the login (home) page, I don't want to log them out but I do want to hide the menu bar. Currently I am using whether the user is authenticated to control if the menu bar is visible or not.
Basically, I want to always hide the menu bar when on the login page. The menu is rendered prior to the page itself so I need to be able to read the redirect request to see if the login page is the destination. I tried a Response.RedirectLocation
field but that seems to be null.
How can I determine what the redirect request is?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为你让事情变得更加复杂了。
如果您使用母版页,只需在母版页中公开一个公共函数,内容页可以调用该函数并隐藏菜单。因此,在您的登录页面中,您将始终调用母版页隐藏菜单功能。
以下是解释如何公开母版页的 MSDN 文章的链接:
http: //msdn.microsoft.com/en-us/library/xxwa0ff0.aspx
编辑: 您需要将 MasterPage 的类命名为 MyMasterPage 之类的名称。然后确保您的 Master 的 aspx 页面中的继承属性是正确的:
然后在您的内容页面中,您应该只添加以下内容:
最后,您现在可以访问母版页中的任何内容,因为您已经定义了它的类型:
应该得到如果您按照以下步骤操作,您就可以工作了。
I think your making this more complicated that it needs to be.
If your using master pages, just expose a public function in your master page that your content page can call and hide your menu. So in your login page you will always call the master pages hide menu function.
Here is a link to an MSDN article explaining how to expose the Master Page:
http://msdn.microsoft.com/en-us/library/xxwa0ff0.aspx
EDIT: You need to name you MasterPage's class something like MyMasterPage. Then make sure your inherits property in your Master's aspx page is correct:
Then in your content page you should be to just add the following:
Lastly you can access anything in your master page now since you have already defined it's type by:
That should get you working if you follow these steps.
使重定向将原始 url 作为 URL 参数发送,例如
Make the redirect send the original url as a URL parameter like
如果您只是想隐藏登录页面上的菜单栏,那么这并不困难。你可以做的就是将 Manu bar 放在 Mater Page 的 ContentPlaceHolder 中。在您的登录页面上,您只需添加空白内容,这将覆盖母版页中的菜单 ContentPlaceholder。
这是Mater 页面上的声明性语法
现在,在其他页面上,您不必覆盖默认内容,该内容显示Mater 页面中您需要显示菜单的菜单。
您可以在此处阅读有关覆盖Mater Page默认内容的更多信息。
If you just wana hide Menu bar on login page then it wont be difficult. What you can do is you put Manu bar inside ContentPlaceHolder in Mater Page. And on your login page you can just add blank Content which will override Menu ContentPlaceholder from Master page.
Here is declarative syntax on Mater page
Now on other pages you do no have to override default content which is showing Menu from Mater page where you need to display Menu.
You can read more about overriding Mater Page's default content over Here.