2009-03-11 5 views
3

사용자 정의 인증과 함께 로그인 컨트롤을 사용하는 .aspx 페이지가 있습니다. 기본적으로 액세스 할 수있는 [UserName] 대신 LoginName 컨트롤을 사용하여 "Welcome [FirstName] [LastName]"메시지를 가질 수 있는지 궁금합니다.ASP.NET LoginName 컨트롤에 전체 이름 표시

불가능할 경우 Session 개체에 이러한 정보를 저장하려고합니다.

감사합니다.

답변

2

RenderContents 메서드를 재정의하거나 고유 한 LoginName 컨트롤을 만들어야합니다. 또한,

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); 
      } 
     } 
} 

working with LoginName에 짧은 기사 여기를 참조 : 이런 식으로 뭔가 트릭을 할 것입니다.

+0

프로필을 사용하지 않고 기본 ASP.NET 공급자를 사용하고 있지 않습니다. 세션 개체에 사용자의 전체 이름을 저장하는 대신에 정착했습니다. 감사! –

2

리디렉션 페이지에서 LoginName 컨트롤을 만들려면 Masterpage.aspx 또는 다른 페이지 일 수 있습니다.

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

다음이 당신을 위해 도움이됩니다

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 
} 

파일 .cs의를 Page_Load 내부 코드의 다음 줄을 삽입 ???

관련 문제