更改 ASP.NET 母版页中的控件

发布于 2024-12-01 05:19:34 字数 203 浏览 0 评论 0 原文

我正在设计一个使用母版页的网站。

我有一个登录文本框和一个用户可以用来登录的标签。这些控件位于我的主页上。

但是,即使用户登录文本框,要求输入电子邮件 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

老街孤人 2024-12-08 05:19:34

如果您使用 FormsAuthentication< /a>,您可以使用 LoginView 根据用户的登录状态显示控件。

<asp:LoginView ID="LoginViewTemplate" runat="server">
     <LoggedInTemplate>
         // Welcome message goes here
     </LoggedInTemplate>
     <AnonymousTemplate>
         // Textboxes and other login stuff goes here
     </AnonymousTemplate>
</asp:LoginView>

If you are using FormsAuthentication, you can use LoginView to display controls according to login state of user.

<asp:LoginView ID="LoginViewTemplate" runat="server">
     <LoggedInTemplate>
         // Welcome message goes here
     </LoggedInTemplate>
     <AnonymousTemplate>
         // Textboxes and other login stuff goes here
     </AnonymousTemplate>
</asp:LoginView>
滴情不沾 2024-12-08 05:19:34

母版页中不应有登录文本框。

如果您出于某种原因拥有它,我建议您为登录页面和登录页面使用不同的母版页。

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.

眼睛会笑 2024-12-08 05:19:34

如果您只是想隐藏它,请将控件放在面板控件中,然后在用户登录时隐藏页面加载时的面板。

因此,当用户登录时,使用登录按钮,为其用户 ID 设置会话变量像这样:

Session("UserID") = <some formula to get number>

然后在母版页的页面加载代码部分中写入:

If not Session("UserID") is nothing then
    pnlLogin.Visible = False
End If

然而,有更好的控件和更正确的方法来执行此类操作,例如登录控件,因此不建议使用此方法。

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:

Session("UserID") = <some formula to get number>

Then in the pageload code section of the master page write:

If not Session("UserID") is nothing then
    pnlLogin.Visible = False
End If

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.

沩ん囻菔务 2024-12-08 05:19:34

这里的解决方案通常是使用模板化控件;这意味着,根据状态,可以显示适当的模板和控件。

在这种情况下,已经存在 LoginView 控件为未经身份验证和经过身份验证的用户公开两个模板。默认情况下,如果将显示登录模板,则在经过身份验证并重新加载页面时,将显示另一个模板,该模板允许您使用 LoginName 控件。

考虑到您已经走到这一步,所提供的链接应该为您提供启动和运行所需的一切信息!然而,这是文章中的片段,显示了相关的标记和可用的属性/事件等:

<asp:LoginView
    EnableTheming="True|False"
    EnableViewState="True|False"
    ID="string"
    OnDataBinding="DataBinding event handler"
    OnDisposed="Disposed event handler"
    OnInit="Init event handler"
    OnLoad="Load event handler"
    OnPreRender="PreRender event handler"
    OnUnload="Unload event handler"
    OnViewChanged="ViewChanged event handler"
    OnViewChanging="ViewChanging event handler"
    runat="server"
    SkinID="string"
    Visible="True|False">
    <AnonymousTemplate>
        <!-- child controls -->
    </AnonymousTemplate>
    <LoggedInTemplate>
        <!-- child controls -->
    </LoggedInTemplate>
    <RoleGroups>
        <asp:RoleGroup
            Roles="string">
                <ContentTemplate>
                    <!-- child controls -->
                </ContentTemplate>
        </asp:RoleGroup>
    </RoleGroups>
</asp:LoginView>

如您所见,此控件提供了足够的抽象以与您自己的身份验证方法保持一致,因为有许多选项可供选择来自 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 the LoginName 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:

<asp:LoginView
    EnableTheming="True|False"
    EnableViewState="True|False"
    ID="string"
    OnDataBinding="DataBinding event handler"
    OnDisposed="Disposed event handler"
    OnInit="Init event handler"
    OnLoad="Load event handler"
    OnPreRender="PreRender event handler"
    OnUnload="Unload event handler"
    OnViewChanged="ViewChanged event handler"
    OnViewChanging="ViewChanging event handler"
    runat="server"
    SkinID="string"
    Visible="True|False">
    <AnonymousTemplate>
        <!-- child controls -->
    </AnonymousTemplate>
    <LoggedInTemplate>
        <!-- child controls -->
    </LoggedInTemplate>
    <RoleGroups>
        <asp:RoleGroup
            Roles="string">
                <ContentTemplate>
                    <!-- child controls -->
                </ContentTemplate>
        </asp:RoleGroup>
    </RoleGroups>
</asp:LoginView>

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文