CS1061:'system.security.principal.iidentity'不包含'getusername'的定义 [英] CS1061: 'system.security.principal.iidentity' does not contain a definition for 'getusername'
本文介绍了CS1061:'system.security.principal.iidentity'不包含'getusername'的定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
CS1061:' System.Security.Principal.IIdentity'不包含定义 ' GetUserName'并且没有扩展方法' GetUserName'接受类型' System.Security.Principal.IIdentity'(你错过了使用指令或汇编参考?)
什么我试过:
在Site.master设计器文件中出现此错误..
- < a runat =serverhref =〜/ Account / Managetitle =Manage your account> Hello,<%:Context.User.Identity.GetUserName()%> ; !
GetUserName()havig错误
Microsoft.AspNet。身份alredy添加
谢谢!
解决方案
从 RyanDev 评论
使用HttpContext.Current.User.Identity.Name
获取UserName
并启用 Windows身份验证 [ ^ ]
< blockquote>不确定你是否已经弄明白了,但是要使用'GetUserName'方法,你可能需要在前端页面上包含Microsoft.AspNet.Identity的命名空间。
VB.NET:
<%@ Import Namespace =Microsoft.AspNet.Identity%>
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!
解决方案
Posting as Solution From RyanDev Comments
useHttpContext.Current.User.Identity.Name
to get theUserName
and Enable the Windows Authentication [^]
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" %>
这篇关于CS1061:'system.security.principal.iidentity'不包含'getusername'的定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文