Click here to Skip to main content
15,867,986 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
C#
CS1061: 'System.Security.Principal.IIdentity' does not contain a definition for 'GetUserName' and no extension method 'GetUserName' accepting a first argument of type 'System.Security.Principal.IIdentity' could be found (are you missing a using directive or an assembly reference?)


What I have tried:

getting this error in Site.master designer file..

  • <a runat="server" href="~/Account/Manage" title="Manage your account">Hello, <%: Context.User.Identity.GetUserName() %> !



GetUserName() havig error
Microsoft.AspNet.Identity alredy added

thank you!
Posted
Updated 10-May-19 6:13am
Comments
Karthik_Mahalingam 9-Aug-16 6:35am    
try
HttpContext.Current.User.Identity.Name
[no name] 9-Aug-16 6:41am    
its not working :(
Karthik_Mahalingam 9-Aug-16 6:45am    
enable windows authentication.
[no name] 9-Aug-16 6:49am    
yes the error went off. now getting this one- System.InvalidOperationException: 'respond' is not a valid script name. The name must end in '.js'. which is in


<asp:ScriptReference Name="MsAjaxBundle" />
<asp:ScriptReference Name="jquery" />
<asp:ScriptReference Name="bootstrap" />
<asp:ScriptReference Name="respond" />
<asp:ScriptReference Name="WebForms.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebForms.js" />
<asp:ScriptReference Name="WebUIValidation.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebUIValidation.js"
Karthik_Mahalingam 9-Aug-16 6:53am    
off topic,
might be the related js file is not referenced.

not sure whether you already figure this out, but to use 'GetUserName' method, you may need to include namespace of "Microsoft.AspNet.Identity" on your front-end page.

VB.NET:
<%@ Import Namespace="Microsoft.AspNet.Identity" %>
 
Share this answer
 
Posting as Solution From RyanDev Comments

use HttpContext.Current.User.Identity.Name to get the UserName and Enable the Windows Authentication [^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900