Check if on Admin Site

Rita Mikusch asked on January 25, 2017 23:31

Hi,

(version 8.0)

I have some code in a request handler that I only want to run on the LIVE site, not the ADMIN site. I check "SiteContext.CurrentSiteName" to make sure it's set to "my_site_name". And I check CMS.PortalEngine.PortalContent.ViewMode to make sure it's set to "LiveSite"

But the code is still running for some admin pages. I printed a message to the event log to test this, and sure enough ViewMode and CurrentSiteName are set to "LiveSite" and "my_site_name" on some of the admin pages.

Is there anything else I can check to see if I'm on an admin page?

Thank you.

Correct Answer

Jan Hermann answered on January 26, 2017 08:07

Maybe the easiest way is to check whether the url starts with /Admin after your domain name (and virtual folder).

0 votesVote for this answer Unmark Correct answer

   Please, sign in to be able to submit a new answer.