Set two applications Program Application A is a Web application, and application B is a Windows service.
Application A generates MSMQ named C (references C if it exists) and inserts records into C.
Application B generates MSMQ named C (references C if it exists) and reads records from C.
The two applications and message queues are on the same server.
The following symptoms occur when two applications are started:
If C does not exist.
It is normal when application a starts and application B starts again.
When application B starts and application a starts again, application a cannot read c. Access denied error. Moreover, the administrator cannot manually delete C.
View the Security Information of C under normal conditions and errors. Different creators are found. This error is caused by the permission.
Add the following when creating or referencing MQ:Code(Red part ).
Messagequeue MQ = NULL;
If (messagequeue. exists (@ ". \ private $ \" + mqname) = false)
{
MQ = messagequeue. Create (@ ". \ private $ \" + mqname, true );
MQ. setpermissions ("Everyone ", messagequeueaccessrights. fullcontrol);
}
Else
{
MQ = new messagequeue (@ ". \ private $ \" + mqname );
}
MQ. formatter = new binarymessageformatter ();
The red part means that when the application is an Asp.net application (Web Application)-then the user is ASPnet, and the message queue established by the system by default is fully controlled by everyone. If you create a message queue for a Windows service or a winform application-if you are not using ASPnet as system or administrator, you must grant permissions to everyone to create a message queue.
The above is for Asp.net. Other web applications can also refer to this idea when competing with Windows applications for MSMQ.