Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8543307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:16:14+00:00 2026-06-11T12:16:14+00:00

I have a web site that uses Membership and form authentication: ASP.NET Page: <asp:LoginView

  • 0

I have a web site that uses Membership and form authentication:

ASP.NET Page:

<asp:LoginView 
    ID="HeadLoginView" ...
    <AnonymousTemplate>
        <asp:Login ID="LoginUser" OnLoggedIn="LoginUser_LoggedIn" ... >
            <LayoutTemplate>
                <asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">Username:</asp:Label>
                <asp:TextBox ID="UserName" runat="server" CssClass="textEntry"></asp:TextBox>
                <asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">Password:</asp:Label>
                <asp:TextBox ID="Password" runat="server" CssClass="passwordEntry" TextMode="Password"></asp:TextBox>
                <asp:CheckBox ID="RememberMe" runat="server"/>
                <asp:Label ID="RememberMeLabel" runat="server" AssociatedControlID="RememberMe" CssClass="inline">Remember me.</asp:Label>
                <asp:Button ID="LoginButton" runat="server" CommandName="Login" Text="Login" style="width:100%; height:35px"/>
            </LayoutTemplate>
        </asp:Login>            
    </AnonymousTemplate>
    ...
</asp:LoginView>

Code behind:

protected void LoginUser_LoggedIn(object sender, EventArgs e)
{
    MembershipUser user = Membership.GetUser();
    if (Roles.IsUserInRole(user.UserName, "User"))
    {
        // Do something and redirect to user page...
    }

    if (Roles.IsUserInRole(user.UserName, "Admin"))
    {
        // Do something and redirect to admin page...
    }
}

The problem is that Membership.GetUser() always returns null. I tried to get username with Page.User.Identity.Name but it is always empty string. Is there a way to find username of currently logged in user or even better: define after-login behavior of <asp:LoginView> or <asp:Login>?

Edit:

MSDN: Login.LoggedIn Event Occurs when the user logs in to the Web site and has been authenticated. (link) So the problem is that why after authenticating user Membership.GetUser() returns null?

One of my colleagues said that instead of using Membership.GetUser() use Membership.GetUser(UserNameTextBox.Text) and it is okay because user is authenticated with this username BUT the problem is that I can not find a way to get Username.Text. I used findControl() and got error.

Any Idea?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T12:16:16+00:00Added an answer on June 11, 2026 at 12:16 pm

    Finally I found the solution based on the Idea of @LolCoder:

    protected void LoginUser_LoggedIn(object sender, EventArgs e)
    {
        String username = (HeadLoginView.FindControl("LoginUser") as Login).UserName;
    
        if (Roles.IsUserInRole(username, "User"))
        {
            //...
        }
        // ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASP.NET MVC 3 web site that uses Windows Authentication running under
We have an MVC3 site that uses the ASP.NET Membership Provider with Forms Authentication
I have website that uses ASP.net Membership Provider. This web site will be served
I have a website that uses basic ASP.Net forms authentication. In the web.config file
I have a ASP.NET MVC site that uses forms authentication with custom AuthorizeAttribute on
I have an existing Web Site that uses multiple ASP .Net Web Forms projects.
I have an ASP.NET MVC intranet site that uses Windows Authentication (Kerberos) exclusively with
I have a ASP.NET MVC4 web api that uses fluent NHibernate, but when I
I've created a web site that uses classic ASP.NET caching: DataSet ds = new
I have made a MVC application that uses the built-in ASP.NET login functions. It

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.