문제

로그인 한 사용자 이름의 사용자 이름을 가져 오려고합니다.아래 코드를 사용하고 있지만 IIS 응용 프로그램 풀 ID에서 자격 증명이 사용되는 사용자를 반환합니다.MVC 웹 사이트는 서버에 배포됩니다.

를 사용했습니다.

string userid = System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();

string userid = Environment.UserName;

string userid = System.DirectoryServices.AccountManagement.UserPrincipal.Current.GivenName.ToString();

string userid = System.Web.HttpContext.Current.User.Identity.Name.ToString()

그러나 아무 것도 정답을주는 것 같습니다.

HomeController의 생성자에서 사용자 이름을 가져와야합니다.

아래의 내 web.config

<authentication mode="Windows" />
<authorization>
    <allow users="*" />
</authorization>
.

도움이 되었습니까?

해결책

대신에
string userid = System.Web.HttpContext.Current.User.Identity.Name.ToString()
.

이를 사용하면 이렇게하면

가 작동합니다.
string userid = HttpContext.Current.User.Identity.Name.ToString() 
.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top