2017-10-06 108 views
0

嗨,我正在做一種遷移其他CMS到sitecore現在。創建sitecore項目爲pdf

所以我的要求是查看各自的URL中的PDF。

現有的網站網址: DOMAIN.COM/pressrelease/one

並在瀏覽器這將顯示PDF內容。

新網站預計網址: NEWDOMAIN.COM/pressrelease/one enter image description here

同樣在我的Sitecore的內容我嘗試在根目錄中創建一個PRESSRELEASE項目及其子是one.pdf。但是當我給像NEWDOMAIN.COM/pressrelease/one這樣的網址時,我無法查看我的pdf。

需要預期的行爲是在瀏覽器中打開pdf文件,就像媒體(/ -/media/pressrelease/one)項目能夠查看。

回答

1

在App_config/include文件夾(如果它不存在)中創建AllowedExtensions.config並添加以下sitecore配置。配置確保通過URL允許使用pdf。

<?xml version="1.0" encoding="utf-8" ?> 
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/"> 
    <sitecore> 
    <pipelines> 
     <preprocessRequest> 
     <processor type="Sitecore.Pipelines.PreprocessRequest.FilterUrlExtensions, Sitecore.Kernel"> 
      <param desc="Allowed extensions (comma separated)">aspx, ashx, asmx, xml, txt,pdf,png</param> 
      <param desc="Blocked extensions (comma separated)">*</param> 
      <param desc="Blocked extensions that stream files (comma separated)">*</param> 
      <param desc="Blocked extensions that do not stream files (comma separated)"/> 
     </processor> 
     </preprocessRequest> 
    </pipelines> 
    </sitecore> 
</configuration> 
0

我曾嘗試使用以下解決方案

  1. 首先我必須創建一個內容項NEWDOMAIN.COM/pressrelease/one解決了我的情況。

  2. 這個項目有兩個字段從我的模板,如下所示。 enter image description here

  3. 然後我對這個內容項目的一些單獨的版式文件,在佈局我創建的代碼顯示PDF文件。(另外,在一些佈局我可以能夠使用這種方法來下載文件了。)

    if(mediaResult.mediaItem != null) 
    { 
        HttpContext.Current.Response.Clear(); 
        HttpContext.Current.Response.ContentType = mediaResult.mediaItem.MimeType; 
        HttpContext.Current.Response.AppendHeader("Content-Disposition", string.Format("inline;filename=\"{0}\"", mediaResult.mediaName)); 
        HttpContext.Current.Response.StatusCode = (int)HttpStatusCode.OK; 
        HttpContext.Current.Response.BufferOutput = true; 
        // Copy the media stream to the response output stream 
        mediaResult.mediaItem.GetMediaStream().CopyTo(HttpContext.Current.Response.OutputStream); 
        // As momma always said: Always remember to flush 
        HttpContext.Current.Response.Flush(); 
        HttpContext.Current.Response.End(); 
    } 
    
相關問題