【问题标题】:FW/1 with Subsystems, Routes and SES带有子系统、路由和 SES 的 FW/1
【发布时间】:2018-02-19 13:45:48
【问题描述】:

我正在尝试使用 FW/1 使用子系统在 ColdFusion 中设置 API 站点。我想设置路由以省略 index.cfm 并使用 /subsystem/action/item 作为默认路径,但我不确定是否有办法做到这一点。文档不是很清楚,从我能找到的内容和其他问题都非常古老。

现在,我的 Application.cfc 中有以下内容...

variables.framework = {
        trace = false,
        reloadApplicationOnEveryRequest = "true",
        home = "main.default",
        diComponent = "framework.ioc",
        diLocations = "/model,/controllers",
        SESOmitIndex = true
};

variables.framework.routes = [
        { "$GET/accounts:member/membercount" = "/account/member/membercount" }
];

这会导致 IIS 中出现 404 错误。有什么建议吗?

更新:我确实发现我需要更新 IIS 以包含 URL 重写以省略 index.cfm,但是,当我尝试调用 http://example.com/account/member/membercount 时仍然得到 404

如果我将 URL 更改为 http://example.com/account:member/membercount,我会收到一个 IIS 错误,“检测到来自客户端 (:) 的潜在危险 Request.Path 值”。

我更愿意以第一种方式调用 URL,使用“/”而不是“:”,但我不知道该怎么做。似乎路线应该能够处理这个问题,但我到目前为止还没有找到方法。

【问题讨论】:

  • accountaccounts?您的Application.cfc sn-p 表示帐户。你的示例链接最后没有s
  • 我只是在玩 FW1 中的子系统并纯粹偶然地搜索互联网我回到这个问题。我曾期望像{ "$GET/accounts/member/membercount/$" = "/account:member.membercount" } 这样的东西会起作用,但它在我的设置中不起作用。可能与路径信息到达应用程序服务器的方式有关。有一些可能的故障点。

标签: routing frameworks cfml subsystem


【解决方案1】:

这已经很晚了,但是:

您似乎正在尝试使用搜索引擎友好的 URL。你的variables.framework 中需要这个generateSES = true

你不需要这个:

variables.framework.routes = [
    { "$GET/accounts:member/membercount" = "/account/member/membercount" }
];

因为这通过使用generateSES 选项变得显而易见。

然后在根文件夹中的web.config文件中

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Rewrite for accounts">
                    <match url="^accounts/(.*)" />
                    <conditions>
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="/accounts:{R:1}" />
                </rule>

                <rule name="RewriteUserFriendlyURL1">
                    <match url="(.*)" />
                    <conditions>
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="index.cfm/{R:1}" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

这告诉 IIS 处理根文件夹中带有 index.cfm 文件的所有 URL(从 URL 中省略 index.cfm)。现在您可以使用您的 FW1 路由来判断执行哪个控制器(如果不明显)。

这还通过将子系统名称旁边的/ 重写为:,从url 结构中删除:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-12-09
    • 1970-01-01
    • 2014-03-26
    • 1970-01-01
    • 2019-05-10
    • 2011-03-06
    • 2013-11-29
    相关资源
    最近更新 更多