aspx页面上HttpContext.Current.Request.Url.Host和HttpContext.Current.Request.Url.Authority之间的三元条件 [英] Ternary condition between HttpContext.Current.Request.Url.Host and HttpContext.Current.Request.Url.Authority on aspx page
问题描述
如何在.aspx页面上的HttpContext.Current.Request.Url.Host和HttpContext.Current.Request.Url.Authority之间使用样式-url标记的三元条件(要检查它是不是本地主机还是不直接) ?
How to use ternary condition with style - url tag, between HttpContext.Current.Request.Url.Host and HttpContext.Current.Request.Url.Authority on .aspx page to (want to check is it localhost or not directly)?
这里是示例:
"div style='<%= "height: 1115px; background-image: url(\"" + "http://" + HttpContext.Current.Request.Url.Host.ToString() +"ImagePath"); background-position: bottom center; background-repeat: no-repeat;" %>'"
我要检查是否
推荐答案
.aspx代码(抱歉,它很长,我无法将其分解成多个而不破坏语法):
this .aspx code (sorry, it's long, I couldn't break it into multiple without breaking syntax):
<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中替换此行:
given that your ImagePath
variabl contains the real path to your image, you need to replace this line in the div:
+ "path/to/image.jpg" +
其中:
+ ImagePath +
不要担心两个 style =
和 url(
包含
,无论如何应该可以。我确认了
Don't worry that both style="
and url("
contain "
, it should work anyways. I confirmed this in Chrome.
HTH
这篇关于aspx页面上HttpContext.Current.Request.Url.Host和HttpContext.Current.Request.Url.Authority之间的三元条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!