【问题标题】:Tridion 2009 SP1: Is it possible to publish a .htaccess file?Tridion 2009 SP1:是否可以发布 .htaccess 文件?
【发布时间】:2012-04-13 19:41:23
【问题描述】:

我在一个项目上使用 ISAPI 重写,想知道是否可以从 Tridion 发布 .htaccess 文件?

我已尝试使用 .htaccess 扩展名创建页面模板,但无法创建没有名称的页面。

有什么想法吗?

我可以使用 C# TBB 来更改页面名称吗?

【问题讨论】:

    标签: tridion


    【解决方案1】:

    我也会选择使用二进制文件来实现这一点,但是如果您想使用文本而不是多媒体组件来管理 htaccess 文件,您可以使用以下技术将二进制文件推送到您的包中:

    1) 将 Htaccess 文件的文本推送到具有可访问名称(即 Binary_Text)的包中 2) 使用类似下面的代码,从变量中的文本创建一个文本文件,并将其添加到包中

    class publishStringItemAsBinary : ITemplate
    {
        public void Transform(Engine engine, Package package)
        {
            TemplatingLogger log = TemplatingLogger.GetLogger(typeof(publishStringItemAsBinary));
            TemplateUtilities utils = new TemplateUtilities();
            System.IO.Stream inputStream = null;
            try
            {
                string strInputName = package.GetValue("InputItem");
                string strFileName = package.GetValue("strFileName");
                string sg_Destination = package.GetValue("sg_Destination");
                string itemComponent = package.GetValue("mm_Component");
    
                inputStream = new MemoryStream(Encoding.UTF8.GetBytes(package.GetValue(strInputName)));
    
                log.Debug("InputObject:" + strInputName);
                log.Debug("Filename for binary:" + strFileName);
                log.Debug("Destination StructureGroup:" + sg_Destination);
                Publication contextPub = utils.getPublicationFromContext(package, engine);
                TcmUri uriLocalSG = TemplateUtilities.getLocalUri(new TcmUri(contextPub.Id), new TcmUri(sg_Destination));
                TcmUri uriLocalMMComp = TemplateUtilities.getLocalUri(new TcmUri(contextPub.Id), new TcmUri(itemComponent));
                StructureGroup sg = (StructureGroup)engine.GetObject(uriLocalSG);
                Component comp = (Component)engine.GetObject(uriLocalMMComp);
                String sBinaryPath = engine.PublishingContext.RenderedItem.AddBinary(inputStream, strFileName, sg, "nav", comp, "text/xml").Url;
                //Put a copy of the path in the package in case you need it
                package.PushItem("BinaryPath", package.CreateStringItem(ContentType.Html, sBinaryPath));
            }
            catch (Exception e)
            {
                log.Error(e.Message);
            }
            finally
            {
                if (inputStream != null)
                {
                    inputStream.Close();
                }
    
            }
        }
    }
    

    我认为代码很容易解释。这会发布 text/xml 类型的二进制文件,但将其转换为纯文本文件应该没有问题。

    【讨论】:

    • 克里斯,我决定暂时将其作为部署任务,但这段代码下次看起来真的很棒。谢谢。
    【解决方案2】:

    我认为您可以使用多媒体组件来存储您的 .htaccess。即使您无法上传没有名称的文件(Windows 限制),您也可以稍后通过修改多媒体组件的BinaryContent.Filename 属性来更改文件名。然后,您可以单独发布此组件,或在您的一个模板中使用AddBinary 方法。

    还有一个用户架构,您可以在其中更改一些其他规则:“\Tridion\bin\cm_xml_usr.xsd”,但您将不能允许空文件名

    【讨论】:

    • 感谢您的回答。目前我只是将其作为一项部署任务,因为我只有一个网站,但将来会寻求实现类似的东西。
    猜你喜欢
    • 1970-01-01
    • 2023-03-04
    • 2012-11-09
    • 2012-05-01
    • 2012-05-18
    • 2012-07-19
    • 1970-01-01
    • 2012-06-24
    • 2012-04-30
    相关资源
    最近更新 更多