2010-04-04 3 views
2

내 페이지에 리소스 관리자를 만들고 리소스 파일에 저장된 일부 데이터를 사용하고 싶습니다.ASP.NET에서 리소스 관리자를 만드는 방법

System.Resources.ResourceManager myResourceManager = System.Resources.ResourceManager.CreateFileBasedResourceManager("resource", 
       Server.MapPath("App_LocalResources") + Path.DirectorySeparatorChar, null); 

    if (User.Identity.IsAuthenticated) 
    { 
     Welcome.Text = myResourceManager.GetString("LoggedInWelcomeText"); 
    } 
    else 
    { 
     Welcome.Text = myResourceManager.GetString("LoggedOutWelcomeText"); 
    } 

을하지만 난 컴파일하고 내 로컬 서버에서 실행할 때이 유형의 오류를 얻을 : (default.aspx.resx 및 default.aspx.en.resx는)

코드는 다음과 같습니다 :

Could not find any resources appropriate for the specified culture (or the neutral culture) on disk. baseName: resource locationInfo: fileName: resource.resources Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

예외 정보 : System.Resources.MissingManifestResourceException는 : 디스크의 지정된 문화에 대한 자원의 적절한 (또는 중립 문화를) 찾을 수 없습니다. baseName의 : 자원 locationInfo : 파일 이름 : resource.resources

소스 오류 :

행 89 : 다른 행 90 : { 행 91 : Welcome.Text = myResourceManager.GetString ("LoggedOutWelcomeText"); 92 번 라인 :} 라인 93 :

이 문제에 대해 저에게 도움을 주시기 바랍니다.

답변

1

MSDN에 따르면 CreateFileBasedResourceManager는 컴파일 된 리소스 파일을 필요로합니다. 대개 App_LocalResources에 .resx 파일을 넣습니다. 이 디렉토리에 resource.XXX.resources (여기서 XXX는 현재 culture ID 임)라는 디렉토리에 파일이 있습니까?

ASP.NET 프로젝트에서 이것을 확인하기 위해 편리한 VS가 없지만 리소스 문자열을 처리하는 일반적인 방법은 프로젝트 속성 인 리소스 탭으로 이동하여 거기에 문자열을 만드는 것입니다. 이렇게하면 리소스 주위에 강력하게 형식화 된 래퍼가 생성되므로 명시 적으로 고유 한 ResourceManager를 만들지 않아도됩니다.

+0

예, default.aspx.en.resx이 있고을 App_LocalResources에 default.aspx.resx도 이름이 "LoggedOutWelcomeText" – Bart

+0

OK 거기 행되지만 이름 돈 ' CreateFileBasedResourceManager에 대한 호출로 말하는 'resource'로 시작하십시오. – Timores

3

GetLocalResourceObject()은 System.Web.Page의 기반입니다. 전역 리소스에 액세스하려면 GetGlobalResourceObject()를 사용하십시오.

유지 그것은 간단한 ;-)