作为旁注(也许它会解决您的问题),如果您不想将 .htc 文件放在您的根目录下,您可以执行以下操作来解决行为固有的相对路径问题。这不是最漂亮的解决方案,但效果很好 -
在您的 css 中,将行为定义为:behavior: url(CSS3PIE);
然后在您的 Global.asax.cs 中有以下代码:
protected void Application_BeginRequest(Object sender, EventArgs e)
{
CheckForCSSPIE();
}
private void CheckForCSSPIE()
{
if (!Regex.IsMatch(Request.Url.ToString(), "CSS3PIE"))
{
return;
}
const string appRelativePath = "~/Content/css/PIE.htc";
var path = VirtualPathUtility.ToAbsolute(appRelativePath);
Response.Clear();
Response.StatusCode = (int)HttpStatusCode.MovedPermanently;
Response.RedirectLocation = path;
Response.End();
}
它只会查找任何匹配“CSS3PIE”的请求并从正确的位置返回 .htc 文件。