【问题标题】:Whats does the ~ mean in a URLURL 中的 ~ 是什么意思
【发布时间】:2013-11-12 01:34:14
【问题描述】:

我有一个使用 Sitecore 用 C# 开发的网站,我有这个 URL:

http://dev.take.com.web.unity.internal.com/~/media/group/images/media/content/19590.ashx?h=180&mh=219&mw=514&w=5120

对于某些图像,我不明白这个 URL 以及 (~) 符号的含义。

【问题讨论】:

标签: c# url sitecore


【解决方案1】:

在 Sitecore 中,~/media/ 是触发媒体处理程序的 URL 前缀,这反过来告诉 Sitecore 该请求是针对媒体库项目的。这些请求的处理方式与对站点根目录下项目的请求不同。

前缀在 web.config 的 sitecore/customHandlers 部分中定义:

<customHandlers>
   <handler trigger="~/media/" handler="sitecore_media.ashx" />
</customHandlers>

如果您决定更改此值,您还需要更新以下设置,以便生成带有新前缀的新链接:

<setting name="Media.MediaLinkPrefix" value="" />

也就是说,如果您已有指向在富文本编辑器中创建的媒体项目的链接,那么添加一个额外的前缀可能更明智,这样默认的~/media/ 前缀仍然有效。要配置其他前缀,请将它们添加到 web.config 的 &lt;mediaPrefixes&gt; 部分,如下所示:

<!-- MEDIA REQUEST PREFIXES
     Allows you to configure additional media prefixes (in addition to the prefix defined by the Media.MediaLinkPrefix setting)
     The prefixes are used by Sitecore to recognize media URLs.
     Notice: For each custom media prefix, you must also add a corresponding entry to the <customHandlers> section
-->
<mediaPrefixes>
  <!-- Example
  <prefix value="-/media"/>
  -->
</mediaPrefixes>

【讨论】:

  • 太好了,谢谢德里克
【解决方案2】:

Specification of the URI: RFC 3986

reserved = gen-delims / sub-delims  
gen-delims  = ":" / "/" / "?" / "#" / "[" / "]" / "@"  
sub-delims  = "!" / "$" / "&" / "'" / "(" / ")"  
                  / "*" / "+" / "," / ";" / "="

它不在保留字符列表中,这意味着它没有什么特别之处。通常它是一个目录的指示。

2.3。无保留字符

URI 中允许但没有保留的字符 目的被称为毫无保留。这些包括大写和小写 字母、十进制数字、连字符、句点、下划线和波浪号。

unreserved  = ALPHA / DIGIT / "-" / "." / "_" / "~"

【讨论】:

    猜你喜欢
    • 2017-02-01
    • 2016-12-18
    • 1970-01-01
    • 1970-01-01
    • 2011-11-18
    • 1970-01-01
    • 2011-01-20
    • 2020-05-21
    • 1970-01-01
    相关资源
    最近更新 更多