2009-06-24 12 views

risposta

17
public static string YourHtmlHelper(this HtmlHelper html) 
{ 
    var name = html.ViewContext.HttpContext.User.Identity.Name; 
} 
5

Si potrebbe voler controllare e vedere se User.Identity è nullo prima di provare ad afferrare il Nome.

public static string YourHtmlHelper(this HtmlHelper html) 
    { 
     var identity = html.ViewContext.HttpContext.User.Identity; 

     if (identity != null) 
     { 
      return html.ViewContext.HttpContext.User.Identity.Name; 
     } 

     return string.Empty; 
    } 
Problemi correlati