I manage to found a way to get current site:
You could get the hostname that configured in IIS:
var hostName = HostingEnvironment.SiteName;
and then loop through the list of SiteDefinition and find the matching hostname
var sites = ServiceLocator.Current.GetInstance<SiteDefinitionRepository>().List(); var site = sites.FirstOrDefault(s => s.Hosts.Any(h => h.Name.Equals(hostName, StringComparison.InvariantCultureIgnoreCase))); return site != null ? site.Name : string.Empty;
But still don't know why Remote event receive twice
I have two questions that seems not able to find the answer from Google.
1. How could we get current site that handling remote event on raised?
2. Why remote event raised from one application, but other application (default one) will always receive the message?
I have multiple sites solution setup locally (3 sites with 3 different application pool), add a simple page that raise remote event and have an event handler to handle that.
The configuration is:
- site1, use wildcard mapping in site setting
- site2 and site3 don't have wildcard.
From site2, the event is raised, but on the raised handler
It always log twice, once for the site that raised the event (which is site2), and one for site1 which has wildcard mapping. site3 didn't receive the event.
Also, SiteDefinition.Current.Name always return site1 because we are lacking of HttpContext on event handler.
Thanks in advance!