저는 C#에 익숙하지 않아서 내 aspx 페이지에 표시 할 수없는 변수에 문제가 있습니다.내 코드에서 .net 페이지에 변수를 전달할 수 없습니다.
코드 뒤에 다음과 같다 :
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using System.DirectoryServices;
using System.DirectoryServices.AccountManagement;
namespace PRIIS
{
public partial class _Default : System.Web.UI.Page
{
private DirectoryEntry GetDirectoryObject()
{
DirectoryEntry oDE;
oDE = new DirectoryEntry("LDAP://192.168.5.4", "user", "xxxx", AuthenticationTypes.Secure);
return oDE;
}
public DirectoryEntry GetUser(string UserName)
{
DirectoryEntry de = GetDirectoryObject();
DirectorySearcher deSearch = new DirectorySearcher();
deSearch.SearchRoot = de;
deSearch.Filter = "(&(objectClass=user)(SAMAccountName=" + UserName + "))";
deSearch.SearchScope = SearchScope.Subtree;
SearchResult results = deSearch.FindOne();
if (!(results == null))
{
de = new DirectoryEntry(results.Path, "user", "xxxx", AuthenticationTypes.Secure);
return de;
}
else
{
return null;
}
}
public class MyUserName
{
public string strName;
public string str;
public void userNameOnSystem()
{
strName = HttpContext.Current.User.Identity.Name.ToString();
string[] splitString = strName.Split('\\');
str = splitString[1];
}
}
protected void Page_Load(object sender, EventArgs e)
{
DirectoryEntry de = GetUser("dramirez");
if (de != null)
{
string displayUser = de.Properties["displayName"].Value.ToString();
Response.Write(displayUser + "<br/>");
//Response.Write(de.Properties["telephoneNumber"].Value.ToString() + "<br/>");
//Response.Write(de.Properties["mail"].Value.ToString() + "<br/>");
//Response.Write(de.Properties["userPrincipalName"].Value.ToString() + "<br/>");
}
}
}
}
그리고 내가 뭐하는 거지 통화가 나는 다음과 같은 문
을 사용하여 .aspx 페이지에 표시 할 displayUser 문자열입니다<%= displayUser %>
불행히도 오류가 발생합니다.
오류 2의 이름 'displayUser'는 현재 컨텍스트
에 존재하지 않는 내가 어디에서 어떻게 문제가에서 오는 모르겠습니다.
도움을 주셔서 감사합니다.
완벽했습니다. 대단히 감사합니다. – richcfml