3

I have an .aspx page using a login control with custom authentication. I was wondering if it's possible to have a "Welcome [FirstName] [LastName]" message using the LoginName control instead of the [UserName] that is accessed by default.

I'm thinking of storing these info in the Session object if it's not possible.

Thanks!

John Feminella
  • 303,634
  • 46
  • 339
  • 357
Leon Tayson
  • 4,741
  • 7
  • 37
  • 36

4 Answers4

2

create a LoginName control in redirect page it may be Masterpage.aspx or any other page.

<asp:LoginName ID="LoginName1" runat="server" />

then insert these line of code inside the page_load in .cs file

protected void Page_Load(object sender, EventArgs e)
{
    //this can come from anywhere like session, database
    string fullName = "ABC XYZ";
    LoginName1.FormatString = "welcome" + " - " + fullName ; //output: welcome - ABC XYZ

    or

    LoginName1.FormatString = fullName; // output: ABC XYZ
}

is this helpful for you???

CuccoChaser
  • 1,059
  • 2
  • 15
  • 27
agiles
  • 1,711
  • 3
  • 17
  • 18
2

You'll need to override the RenderContents method or make your own LoginName control. Something like this will do the trick:

protected override void RenderContents(HtmlTextWriter writer)
{
      if (string.IsNullOrEmpty(Profile.FullName))
            return;

      nameToDisplay = HttpUtility.HtmlEncode(Profile.FullName);
      string formatExpression = this.FormatString;
      if (formatExpression .Length == 0)
      {
            writer.Write(nameToDisplay);
      }
      else
      {
            try
            {
                  writer.Write(string.Format(CultureInfo.CurrentCulture, formatExpression, new object[1] { nameToDisplay });
            }
            catch (FormatException exception)
            {
                  throw new FormatException("Invalid FormatString", exception1);
            }
      }
}

Also, see here for a brief article on working with LoginName.

John Feminella
  • 303,634
  • 46
  • 339
  • 357
0

You could use the FormatString property to set the welcome message to any string you want. When combined with expression builders (e.g. <%$ expressionPrefix: expressionValue %>) you would have a flexible way to define output.

Daniel Ballinger
  • 13,187
  • 11
  • 69
  • 96
0

First of all, see Personal names in a global application: What to store. Even if your site is limited to the US, I'm pretty sure I've seen some foreigners around here.

Community
  • 1
  • 1
John Saunders
  • 160,644
  • 26
  • 247
  • 397