带有IIS URL重写的ColdFusion - 页面永远不会完成加载

时间:2013-09-16 22:39:41

标签: coldfusion iis-7.5 coldfusion-10 url-rewrite-module

我在IIS 7.5上运行CF10并安装了URL Rewrite模块。 所有重写规则都能正常工作,ColdFusion正在返回正确的页面。为了在浏览器中显示页面,我必须在Application.cfc中手动设置'content-length'值,如下所示:

<cfcomponent>

  <cffunction name="onRequestEnd">

  <cfheader name="Content-Length" value="#getPageContext().getCFOutput().getBuffer().size()#" />

  </cffunction>

</cfcomponent>

如果没有此代码,浏览器将不显示该页面。但是,即使它现在正在显示页面,它也没有正确执行。该页面永远不会完全加载,并且并非所有HTML内容都显示在页面上。

我在设置'content-length'后尝试添加<cfflush />标记,但没有区别。我不明白为什么会这样,但我知道发生在使用htaccess的其他人身上:http://forums.devshed.com/coldfusion-development-84/page-not-finishing -loading-coldfusion-and-htaccess-bug-575906.html

编辑:示例出站/入站规则定义:

<!--- Outbound rule --->
<rule name="Rewrite Info Page" preCondition="IsHTML" enabled="false" stopProcessing="false">
<match filterByTags="A" pattern="^(.*)/info\.cfm\?subjectid=([^=&amp;]+)&amp;(?:amp;)?nameid=([^=&amp;]+)$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
</conditions>
<action type="Rewrite" value="{R:1}/info/{R:2}/{R:3}" />
</rule>

<preConditions>
<preCondition name="IsHTML">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
</preCondition>


<!--- Inbound rule --->
<rule name="Rewrite Info Page" enabled="true" stopProcessing="false">
<match url="^(.*)/info/([^/]+)/([^/]+)/?$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="{R:1}/info.cfm?subjectid={R:2}&amp;nameid={R:3}" appendQueryString="true" />
</rule>

出站规则正在查看<a>标记内的http://mysite.com/info.cfm?subjectid=1&nameid=1标记中的网址链接,然后将其重写为http://mysite.com/info/1/1在我的网页上显示。

Inbound正在寻找类似于http://mysite/info/1/1的链接,并将其解析/重写为真实的网址http://mysite.com/info.cfm?subjectid=1&nameid=1

2 个答案:

答案 0 :(得分:1)

我能够让你的出站规则在我的本地开发环境中运行(尽管运行CF9)。唯一的麻烦是将出站规则包装在正确的XML元素中。

之后,IIS告诉我出站规则无法应用于gzip压缩内容,所以我不得不在配置中添加<urlCompression doStaticCompression="true" doDynamicCompression="false"/>

有了这个,出站重写就完美了。我甚至在一个有超过20,000个链接的页面上运行它,它处理得很好。

以下是我的<rewrite>部分,其中包含web.config以及<urlCompression>位:

    <rewrite>
        <rules>
            <rule name="Rewrite Info" enabled="true" stopProcessing="false">
                <match url="^(.*)/info/([^/]+)/([^/]+)/?$" />
                <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                </conditions>
                <action type="Rewrite" url="{R:1}/info.cfm?subjectid={R:2}&amp;nameid={R:3}" appendQueryString="true" />
            </rule>
        </rules>
        <outboundRules>
            <rule name="Rewrite Info Page" preCondition="IsHTML" enabled="true" stopProcessing="false">
                <match filterByTags="A" pattern="^(.*)/info\.cfm\?subjectid=([^=&amp;]+)&amp;(?:amp;)?nameid=([^=&amp;]+)$" />
                <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                </conditions>
                <action type="Rewrite" value="{R:1}/info/{R:2}/{R:3}" />
            </rule>
            <preConditions>
                <preCondition name="IsHTML">
                    <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
                </preCondition>
            </preConditions>
        </outboundRules>
    </rewrite>
    <urlCompression doStaticCompression="true" doDynamicCompression="false"/>

我在<cfheader name="Content-Length" value="#getPageContext().getCFOutput().getBuffer().size()#" />中包含onRequestEnd时发现结果没有差异。

但是,由于您正在获取微调器并且页面似乎永远不会完全加载,您可能会尝试在onRequestEnd中显式刷新并关闭响应,以确保切换回IIS完成:

<cfscript>
    var response = getPageContext().getResponse().getResponse();
    var out = response.getOutputStream();
    out.flush();
    out.close();
</cfscript>

答案 1 :(得分:1)

由于IIS URL Rewrite的出站规则给你带来了很多麻烦,所以这是另一种选择。使用ColdFusion重写onRequestEnd中的链接。这将允许您在IDE中使用物理路径,使用默认文档,并仍然以所需格式获取发送到浏览器的出站URL。我updated my Gist with the details

这是一个非常基本的方法。关闭web.config中的出站重写规则,并将此类内容添加到onRequestEnd中的Application.cfc函数中。 (我的正则表达式很糟糕,所以这个reReplace()模式只能部分地运行你的IIS模式。

<cfcomponent>

    <cffunction name="onRequestEnd">
        <!--- Get the generated output --->
        <cfset var output = getPageContext().getCFOutput().getBuffer().toString()>      

        <!--- Apply outbound link rules --->
        <cfset output = reReplace(output, '/info\.cfm\?subjectid=([^=&amp;]+)', '/info/\1', 'all')>

        <!--- Clear the previous output and send the rewritten output in its place --->
        <cfcontent reset="true">
        <cfoutput>#output#</cfoutput>

    </cffunction>

</cfcomponent>

这不会像IIS中的URL Rewrite模块那样好,但它会为您提供您想要实现的所有其他功能(一旦您调整了正则表达式)。