2012-07-20 2 views
0

ASP.NET 응용 프로그램에서 RabbitMQ의 기본 클라이언트를 사용하여 메시지 큐에 쓰기를하고 싶습니다. 이렇게하려면 RabbitMQ dll을 웹 응용 프로그램의/bin 디렉토리에 넣고 .aspx 테스트 페이지를 만들었습니다.공유 구성을 사용할 때 IIS 7.5의 코드 액세스 보안 예외

나는 다음과 같은 예외 System.Security.SecurityException를 얻을 스크립트를 테스트 할 때 : 중립 System.Security.Permissions.EnvironmentPermission, mscorlib에, 버전 = 2.0.0.0, 문화 = '형식의 허가를 요청, PublicKeyToken = b77a5c561934e089 '실패했습니다.

나는 DLL이 다른 컴퓨터의 공유 디렉터리에 물리적으로 저장되어 있기 때문에이 문제가 발생했다고 생각합니다. 연구를 통해 코드 액세스 보안 정책을 조정할 수있었습니다.

c:\Windows\Microsoft.NET\Framework\v2.0.50727\CasPol.exe -m -ag 1 -url "file://\\server\IISSharedContent\webfarm\stage\dev-stage\bin\*" FullTrust -exclusive on 

작동하지 않는 IIS를 다시 시작한 후.

나는 또한 시도했다 :

  • 은 Web.config의
  • 에 추가 사실
  • 에 응용 프로그램 풀 "로드 사용자 프로필 설정"네트워크 서비스
  • 에 응용 프로그램 풀 ID를 설정

누구에게 도움이 될만한 통찰력이 있습니까?


전체 스택 추적 : 내 테스트 스크립트에 대한

[SecurityException: Request for the permission of type 'System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.] 
     System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) +0 
     System.Security.CodeAccessPermission.Demand() +54 
     System.Environment.GetEnvironmentVariable(String variable) +135 
     RabbitMQ.Client.Protocols.ReadEnvironmentVariable() +22 
     RabbitMQ.Client.Protocols.FromEnvironment(String appSettingsKey) +37 
     RabbitMQ.Client.ConnectionFactory..ctor() +176 
     ASP.api_messagesearch_aspx.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in \\server\iissharedcontent\webfarm\stage\dev-stage\api\MessageSearch.aspx:9 
     System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +115 
     System.Web.UI.Page.Render(HtmlTextWriter writer) +38 
     System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +11070247 
     System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +11069786 
     System.Web.UI.Page.ProcessRequest() +91 
     System.Web.UI.Page.ProcessRequest(HttpContext context) +240 
     ASP.api_messagesearch_aspx.ProcessRequest(HttpContext context) in c:\Windows\Microsoft.NET\Framework64\v2.0.50727\Temporary ASP.NET Files\root\cb973a2c\79ccea1e\App_Web_x0q-uejx.0.cs:0 
     System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +599 
     System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +171 

코드 :

ConnectionFactory rabbitConFactory = new ConnectionFactory(); 
rabbitConFactory.Address = "hostname"; 
rabbitConFactory.VirtualHost = "/path"; 
rabbitConFactory.UserName = "user"; 
rabbitConFactory.Password = "password"; 

IConnection connection = rabbitConFactory.CreateConnection(); 

IModel channel = connection.CreateModel(); 

Dictionary<String, Object> args = new Dictionary<string, object>(); 
args.Add("x-ha-policy", "all"); 
String ExchangeName = "SearchInstructions"; 
channel.ExchangeDeclare(ExchangeName, "topic", true, false, args); 

Guid myId = new Guid(); 
String RoutingKey = myId.ToString() + ".Instruction"; 
IBasicProperties MessageProperties = channel.CreateBasicProperties(); 
MessageProperties.SetPersistent(true); 
MessageProperties.ContentEncoding = "UTF-8"; 
MessageProperties.ContentType = "text/xml"; 
MessageProperties.Headers.Add("x-origin", 
Request.ServerVariables["ServerName"]); 

String messageContent = "<foo />"; 
byte[] data = System.Text.Encoding.UTF8.GetBytes(messageContent); 
channel.BasicPublish(ExchangeName,RoutingKey, MessageProperties, data); 

channel.Close(); 
connection.Close(); 

답변

0

좋아 두 시간 더 나은 부분이 문제로 고생 한 나는 함께했다 간단하고 분명한 해결책 :

32 비트와 64 비트를 모두 사용하십시오. caspol.exe의 버전

이 공유에 대한 신뢰를 올바르게 설정하려면 caspol.exe를 두 번 실행해야했습니다.

c:\Windows\Microsoft.NET\Framework\v2.0.50727\CasPol.exe -m -ag 1 -url "file://\\server\IISSharedContent\webfarm\stage\dev-stage\bin\*" FullTrust 

그리고 내가 IIS 보라를 다시 시작

c:\Windows\Microsoft.NET\Framework64\v2.0.50727\CasPol.exe -m -ag 1 -url "file://\\server\IISSharedContent\webfarm\stage\dev-stage\bin\*" FullTrust 

을 실행, 모든 것이 (다른 버그에서 잘 제외하고) ... 챔피언처럼 일했다.

관련 문제