码迷,mamicode.com
首页 > Windows程序 > 详细

c# 字体库跨域解决

时间:2015-08-10 19:46:55      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:

网上大部分的资料说的都是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", "*");
                }
            }
            
            
        }

 

c# 字体库跨域解决

标签:

原文地址:http://www.cnblogs.com/fuyujian/p/4718772.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!