标签:
网上大部分的资料说的都是在apache和ng服务器的情况下解决方案,但基本的思路都是添加响应头
场景:
页面引用css文件:
<link href="http://www.tuohuangzu.com/content/Company_v2/register/css/font.css" type="text/css" rel="stylesheet"/>
样式中定义:
@font-face {
font-family: ‘Uninf-icon-usual‘;
src:url(‘fonts/Uninf-icon-usual.eot?-ny5g1a‘);
src:url(‘fonts/Uninf-icon-usual.eot?#iefix-ny5g1a‘) format(‘embedded-opentype‘),
url(‘fonts/Uninf-icon-usual.ttf?-ny5g1a‘) format(‘truetype‘),
url(‘fonts/Uninf-icon-usual.woff?-ny5g1a‘) format(‘woff‘),
url(‘fonts/Uninf-icon-usual.svg?-ny5g1a#Uninf-icon-usual‘) format(‘svg‘);
font-weight: normal;
font-style: normal;
}
对字体库的应用导致了跨域,在火狐中会提示ttf和woff引发跨域问题
解决方法:
protected void Application_BeginRequest(object sender, EventArgs e) { var url = HttpContext.Current.Request.Url.AbsolutePath; if (url.LastIndexOf(".", StringComparison.Ordinal) > 0) { var str = url.Substring(url.LastIndexOf(".", StringComparison.Ordinal)); if (str == ".ttf" || str == ".woff") { HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*"); } } }
标签:
原文地址:http://www.cnblogs.com/fuyujian/p/4718772.html