【问题标题】:How to check in ASP.NET MVC View if site is running on localhost or 127.0.0.1如果站点在 localhost 或 127.0.0.1 上运行,如何检查 ASP.NET MVC 视图
【发布时间】:2010-07-09 03:44:06
【问题描述】:

如果站点在 localhost 或 127.0.0.1 上运行,如何检查 ASP.NET MVC 视图?

【问题讨论】:

    标签: asp.net asp.net-mvc


    【解决方案1】:

    您可以使用HttpRequest.IsLocal 属性

    【讨论】:

    • 这就是我要找的!谢谢。
    【解决方案2】:
    @if (Request.IsLocal) { // do something }
    

    <% if (Request.IsLocal) { // do something } %>
    

    【讨论】:

      【解决方案3】:
             <% if (Request.Url.DnsSafeHost.Contains("localhost") || Request.UserHostName.Contains("127.0.0.1"))
             {
      
             } %>
      

      【讨论】:

        【解决方案4】:

        对于 global.asax

        if (System.Diagnostics.Debugger.IsAttached){themeName = ConfigurationManager.AppSettings["ThemeName"];}
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2014-02-27
          • 2015-01-28
          • 2021-06-02
          • 1970-01-01
          相关资源
          最近更新 更多