如何在 ColdFusion 中检查请求的 URL

How check the requested URL in ColdFusion

我在 Application.cfc 的 onRequestStart 方法中编写了下面的代码。因此,每当请求在会话值创建之前出现时,它总是会重定向到 login_action.cfm.

<cfif not IsDefined("session.active")>
   <cfinclude template="login_action.cfm">
</cfif>

login_action.cfm 中是用于阻止未经适当身份验证访问其他页面的代码:

<cfif NOT (IsDefined ("Form.username") AND IsDefined ("Form.password"))>
     <cfinclude template="login.cfm">
     <cfabort>
<cfelse>

现在我创建了一个注册页面。此页面不需要身份验证。每个人都应该可以通过单击进入该页面,但现在不登录是不可能的。我可以通过检查 onRequestStart 方法的 targtedPage 参数来更改它吗?

有人可以帮助我吗?

问题:

Can I check with this by the targtedPage (sic) argument of onRequestStart method?

回答

是的。

使用您现有的代码结构并假设调用您的注册页面signup_page.cfm您可以执行以下操作。

<cffunction 
    name="OnRequestStart" 
    access="public" 
    returntype="boolean" 
    output="false" 
    hint="Fires at first part of page processing.">

    <!--- Define arguments. --->
    <cfargument 
        name="TargetPage" 
        type="string" 
        required="true" />


    <cfif FindNoCase( "signup_page.cfm", arguments.TargetPage)>
        <!--- User is at the signup page, no need to check for an active session. Do stuff if necessary here. --->
    <cfelse>

        <cfif not IsDefined("session.active")>
            <!--- User's session is inactive, redirect --->
            <cfinclude template="login_action.cfm">
            <cfreturn false />  <!--- You should add this return in your existing code. --->
        </cfif>

        <!--- User is logged in with an active session, do other stuff. --->

    </cfif>

    <!--- Return out. --->
    <cfreturn true />

</cffunction>