c#
  • asp.net
  • webforms
  • .net-3.5
  • 2017-02-16 37 views 1 likes 
    1

    如何使用样式-URL标记,HttpContext.Current.Request.Url.Host和HttpContext.Current.Request.Url.Authority on .aspx页面(想要检查它是否是localhost或不是直接)?三元条件之间的HttpContext.Current.Request.Url.Host和HttpContext.Current.Request.Url.Authority aspx页

    这里是例子:

    "div style='<%= "height: 1115px; background-image: url(\"" + "http://" + HttpContext.Current.Request.Url.Host.ToString() +"ImagePath"); background-position: bottom center; background-repeat: no-repeat;" %>'" 
    

    我要检查它是否为localhost,然后它会采取管理局,如果没有,那么它必须采取主机。

    +0

    你可以发表你想要的样本。 –

    +0

    @PatrickHofman - 在我的项目中添加了一个div标签。 –

    回答

    0

    此的.aspx代码(抱歉,这是很长,我不能打破它分成多个不破坏语法):

    <div style='<%= "height: 1115px; background-image: url(\"http://" + (HttpContext.Current.Request.Url.Host.ToString().Contains("localhost") ? HttpContext.Current.Request.Url.Authority : HttpContext.Current.Request.Url.Host) + "/" + "path/to/image.jpg" + "\"); background-position: bottom center; background-repeat: no-repeat;" %>'>my_div_content</div> 
    

    会产生这样的结果:

    <div style="height: 1115px; background-image: url("http://lc.host.com/path/to/image.jpg"); background-position: bottom center; background-repeat: no-repeat;">my_div_content</div> 
    

    给您ImagePath variabl包含图像的真实路径,你需要在div替换该行:

    + "path/to/image.jpg" + 
    

    这个:

    + ImagePath + 
    

    不要担心,这两个style="url("包含",应该反正工作。我在Chrome中确认了这一点。

    HTH

    +0

    它适合我。感谢您的合适解决方案! –

    -1

    伪代码:

    HttpContext.Current.Request.Url.Contains( “localhost” 的)? ... ...

    +0

    我喜欢没有解释的downvotes:D – Dexion

    相关问题