我正在设计一个使用母版页的网站。
我有一个登录文本框和一个用户可以用来登录的标签。这些控件位于我的主页上。
但是,即使用户登录文本框,要求输入电子邮件 ID 和密码的标签也会显示在下一页中,我在成功登录后重定向。
在用户之后,我想隐藏登录标签和文本框,而是显示欢迎用户消息。
但我无法在重定向的下一页中进行编辑。我该如何隐藏它?
I am designing a website that uses a master page.
I have a login text box and a label a user can use to login. These controls are on my master page.
However, even after the user logs in the text box and label asking for email id and password is displayed in next page where I redirect after succesful login.
After a user, I want to hide the login label and text box and instead display a welcome user message.
But I am not able to edit in next page where I redirect. how do I hide that?
发布评论
评论(4)
如果您使用
FormsAuthentication
< /a>,您可以使用LoginView
根据用户的登录状态显示控件。If you are using
FormsAuthentication
, you can useLoginView
to display controls according to login state of user.母版页中不应有登录文本框。
如果您出于某种原因拥有它,我建议您为登录页面和登录页面使用不同的母版页。
You should not have a login textbox in the master page.
If you have it for some reason, I would suggest that you have different master pages for login pages and logged in pages.
如果您只是想隐藏它,请将控件放在面板控件中,然后在用户登录时隐藏页面加载时的面板。
因此,当用户登录时,使用登录按钮,为其用户 ID 设置会话变量像这样:
然后在母版页的页面加载代码部分中写入:
然而,有更好的控件和更正确的方法来执行此类操作,例如登录控件,因此不建议使用此方法。
If you just want to hide it, put the controls in a panel control, then hide the panel on page load if the user is logged in.
So when the user logs in, using the login button, set a session variable for their user id like this:
Then in the pageload code section of the master page write:
There are however better controls, and more correct ways of doing this type of action such as the login controls, so this method is not recommended.
这里的解决方案通常是使用模板化控件;这意味着,根据状态,可以显示适当的模板和控件。
在这种情况下,已经存在
LoginView
控件为未经身份验证和经过身份验证的用户公开两个模板。默认情况下,如果将显示登录模板,则在经过身份验证并重新加载页面时,将显示另一个模板,该模板允许您使用LoginName
控件。考虑到您已经走到这一步,所提供的链接应该为您提供启动和运行所需的一切信息!然而,这是文章中的片段,显示了相关的标记和可用的属性/事件等:
如您所见,此控件提供了足够的抽象以与您自己的身份验证方法保持一致,因为有许多选项可供选择来自 ASP.NET。
The solution here is usually to use a templated control; this means that, depending on the status, the appropriate template, and hence controls can be displayed.
In this case, there is already the
LoginView
control which exposes both templates for the unauthenticated and authenticated users. By default, if will display the login template, then, when authenticated and upon reloading the page, another template will be shown which allows you to display the logged-in users name by using theLoginName
control.The links provided should give you everything you need to know to get this up and running, considering you have brought yourself this far! However, this is the snippet from the article, showing related mark-up and available properties / events, etc:
As you can see, this control provides enough to abstract to align with your own method of authentication, since there are numerous options to choose from with ASP.NET.