Try our conversational search powered by Generative AI!

Get current site on Remote event Raised event handler



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

public void Initialize(InitializationEngine context)
            var event = Event.Get("Guid");
            event.Raised += OnEventRaised;
protected void OnEventRaised(object sender, EventNotificationEventArgs e)
_logger.Error("Current site: " + SiteDefinition.Current.Name);

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!


Mar 26, 2015 11:15

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

Edited, Mar 26, 2015 13:35
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.