33

How to check in ASP.NET MVC View if site is running on localhost or 127.0.0.1?

CDspace
  • 2,639
  • 18
  • 30
  • 36
Alexey Zakharov
  • 24,694
  • 42
  • 126
  • 197

4 Answers4

46

You can use the HttpRequest.IsLocal Property

Aristos
  • 66,005
  • 16
  • 114
  • 150
26
@if (Request.IsLocal) { // do something }

or

<% if (Request.IsLocal) { // do something } %>
LaundroMatt
  • 2,158
  • 1
  • 19
  • 20
2
       <% if (Request.Url.DnsSafeHost.Contains("localhost") || Request.UserHostName.Contains("127.0.0.1"))
       {

       } %>
willbt
  • 1,875
  • 13
  • 11
1

for global.asax

if (System.Diagnostics.Debugger.IsAttached){themeName = ConfigurationManager.AppSettings["ThemeName"];}
Oğuzhan Sari
  • 89
  • 1
  • 9