Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8275865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:12:23+00:00 2026-06-08T08:12:23+00:00

I’d like to have an ASP.NET application write to a message queue using RabbitMQ’s

  • 0

I’d like to have an ASP.NET application write to a message queue using RabbitMQ’s native client. To do this I’ve put the RabbitMQ dll in the /bin directory of my web application, and created an .aspx test page.

When I test the script I get the following exception System.Security.SecurityException: Request for the permission of type ‘System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089’ failed.

Looking into the problem further I believe this is being caused because the dll is physically stored on a shared directory on another computer. Research led me to adjusting the Code Access Security policy by doing:

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

After restarting IIS that doesn’t seem to have worked.

I’ve also tried:

  • Setting the application-pool identity to Network Service
  • Setting the application-pool “Load User Profile” to True
  • Adding to the web.config

Does anyone have any insight which could help me?


Full Stack Trace:

[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

Code for my test script:

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();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T08:12:24+00:00Added an answer on June 8, 2026 at 8:12 am

    Okay having struggled with this problem for the better part of two hours I came up with a simple and obvious solution:

    Use both the 32 and 64 bit versions of caspol.exe

    In order to properly set the trust for this share I had to run caspol.exe twice.

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

    And then Run

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

    I restarted IIS and lo, everything worked like a champ… (well aside from some other bugs).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have thousands of HTML files to process using Groovy/Java and I need to
I am trying to loop through a bunch of documents I have to put
I have two tables with like below codes: Table: Accounts id | username |
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.