문제

사용 방법을 알 수 없습니다 Profile.GetProfile() 라이브러리 클래스의 메소드. 이 메소드를 Page.aspx.cs에서 사용하려고 시도했는데 완벽하게 작동했습니다.

Page.aspx.cs에서 작동하는 방법을 어떻게 만들고, 클래스 라이브러리에서 작업 할 수 있습니까?

도움이 되었습니까?

해결책

asp.net에서 프로파일은 훅입니다 httpcontext.current.profile ProfileCommon의 동적으로 생성 된 객체를 반환하는 속성. System.Web.profile.profilebase.

ProfileCommon은 분명히 GetProfile (String username) 메소드를 포함하지만 MSDN에서 공식적으로 문서화되지는 않을 것입니다 (그리고 Visual Studio의 Intellisense에 표시되지 않음) 대부분의 ProfileCommon 클래스는 ASP.NET 응용 프로그램이 컴파일 될 때 동적으로 생성되기 때문입니다. 정확한 속성 및 메소드 목록은 Web.config에서 '프로파일'이 구성되는 방식에 따라 다릅니다). getProfile ()이 MSDN 페이지에 언급됩니다., 그래서 그것은 진짜 인 것 같습니다.

아마도 라이브러리 클래스에서 문제는 web.config의 구성 정보가 선택되지 않았다는 것입니다. 라이브러리 클래스가 웹 응용 프로그램을 포함하는 용매의 일부입니까, 아니면 도서관에서 분리하여 작업하고 있습니까?

다른 팁

참조를 추가해 보셨습니까? System.Web.dll 수업 도서관에 다음 :

if (HttpContext.Current == null) 
{
    throw new Exception("HttpContext was not defined");
}
var profile = HttpContext.Current.Profile;
// Do something with the profile

프로파일베이스를 사용할 수 있지만 유형 안전성을 잃습니다. 신중한 캐스팅 및 오류 처리로이를 완화 할 수 있습니다.

    string user = "Steve"; // The username you are trying to get the profile for.
    bool isAuthenticated = false;

        MembershipUser mu = Membership.GetUser(user);

        if (mu != null)
        {
            // User exists - Try to load profile 

            ProfileBase pb = ProfileBase.Create(user, isAuthenticated);

            if (pb != null)
            {
                // Profile loaded - Try to access profile data element.
                // ProfileBase stores data as objects in a Dictionary 
                // so you have to cast and check that the cast succeeds.

                string myData = (string)pb["MyKey"];

                if (!string.IsNullOrWhiteSpace(myData))            
                {
                    // Woo-hoo - We're in data city, baby!
                    Console.WriteLine("Is this your card? " + myData);
                }
            }        
        }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top