防止链接其他网站的 css
我的网站上有一个 commerce css。我使用 IIS,供应商说其他人可以使用我的 css 字体,因为他们知道 url。是否可以设置服务器或其他东西,以便只有我的网站可以使用它?是关于cufon的
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
我的网站上有一个 commerce css。我使用 IIS,供应商说其他人可以使用我的 css 字体,因为他们知道 url。是否可以设置服务器或其他东西,以便只有我的网站可以使用它?是关于cufon的
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(4)
如果您使用的是 IIS7 或更高版本,则无需编写任何自定义代码,只需使用 此处。但是,作为简单的引用检查,它具有其他答案中讨论的缺点。
(有关 IIS URL 重写的介绍,请参阅此处.)
摘自第一个链接:
我可能会定制您的重写配置,以便它仅在您的字体 URL(以及其他相关的静态资产)上执行,而不是在每个传入请求上执行。
如果您没有远程桌面访问权限或只是编辑
web.config
,您的重写规则可能类似于:在本示例中,我选择完全阻止请求(通过
AbortRequest< /code>),但是您也可以重定向到带有友好通知的页面。
If you are on IIS7 or greater you can perform a Referer check without writing any custom code, simply by using IIS URL Rewrite in the manor discussed here. However as simply a Referer check, it has the shortcomings discussed in the other answers given.
(For introduction to IIS URL Rewrite see here.)
Excerpt from the first link:
I would probably tailor your Rewrite configuration so that it is only performed on your font URLs (and other static assets of concern) rather than every single incoming request.
If you don't have remote desktop access or are just editing
web.config
, your rewrite rule will probably look something like:In this example I choose the block the request entirely (through
AbortRequest
), however you could just as well have redirected to a page with a friendly notice.不可靠。为了提供嵌入字体,它们需要可供公众阅读,并可由 CSS 引用。
您可以做的是创建一个 asp.net 页面,或者一个处理程序,它接受字体文件的参数,从网站中的某个位置读取文件(APP_DATA 是放置它们的好地方 - 您无法浏览到 APP_DATA )然后吐出来。在脚本中,您可以检查 HTTP_REFERER 服务器端变量,如果它为空,或者来自您的站点,则您将提供文件服务器,如果不是,则不会。
MSDN 有一个如何在 C# 中提供二进制文件的示例。您需要确保 MIME 类型正确,但请注意,这可能会破坏浏览器或代理提供的任何缓存。这也不会阻止人们通过在浏览器中输入 URL 并将其保存在本地来下载字体,但如果带宽是问题所在,那么这并不是真正的问题。
如果您使用的是 IIS7,您可以编写一个 Http 模块来为您执行引荐来源网址检查,Scott Hansleman 为 图像盗取预防 很久以前,您可以编辑它以符合您的目的。
Not reliably. In order to serve up the embedded fonts they need to readable by the public, and referable by your CSS.
What you could do is create an asp.net page, or a handler which takes a parameter of the font file, reads the file from somewhere in your web site (APP_DATA is a good place to put them - you can't browse to APP_DATA) and spits it out. In the script you could check the HTTP_REFERER server side variable and if it is either blank, or comes from your site you server the file, if it doesn't you don't.
MSDN has an example of how to serve up a binary file in C#. You'll need to ensure you get the MIME type right, however be aware this would probably break any caching provided by the browser or proxies. This also wouldn't stop people downloading the fonts by typing the URL into their browser and saving them locally, but if bandwidth is the concern that's not really going to be a problem.
If you're on IIS7 you could write an Http Module which would do the referrer check for you, Scott Hansleman wrote one for image leeching prevention quite a while ago, you could edit that to match your purposes.
您可以创建一个 http 处理程序来提供 css 文件。在自定义 http 处理程序中,检查 request.Url.Host 是否等于 request.UrlReferrer.Host。如果它们不匹配,请将响应设置为 404 或提供一个空的 css 文件。
这未经测试,但应该接近您的需要。
您可以添加一个 css 链接,例如:
You could make an http handler to serve up css files. In your custom http handler, check that the request.Url.Host equals request.UrlReferrer.Host. If they don't match, set the response to 404 or serve up an empty css file.
This is untested but should be close to what you would need.
You would add a link to css like:
你可以做的事情:
UserControl
,将位图粘贴到您放置的任何位置,因此实际上不需要做或维护太多工作。不过,它确实增加了页面的带宽要求。它还迫使您手动进行一些通常由浏览器处理的布局,这可能会增加大量的维护成本或最小的维护成本,具体取决于您网站的布局如何工作。与#2 一样,它可能会对用户的浏览体验产生负面影响。它还会损害可访问性,尽管这并不荒谬,因为您的UserControl
可能会使用替代文本来复制文本。我强烈推荐#1。
Things you can do:
UserControl
that sticks a bitmap where-ever you put it, so this isn't actually that much work to do or maintain. It does increase the bandwidth requirements for your page, though. It also forces you to do some of the layout by hand that is normally handled by the browser, which could add heavy maintenance costs or minimal maintenance costs, depending on how your site's layout works. And as with #2, it can have a negative impact on browsing experience of your users. It also hurts accessibility, though not absurdly so since yourUserControl
will presumably use alt text to duplicate the text.I strongly recommend #1.