如何在ColdFusion中检查请求的URL

Abh*_*jan 3 coldfusion

我在onRequestStartApplication.cfc 的方法中编写了下面的代码.因此,只要在创建会话值之前发出请求,它就会始终重定向到login_action.cfm.

<cfif not IsDefined("session.active")>
   <cfinclude template="login_action.cfm">
</cfif>
Run Code Online (Sandbox Code Playgroud)

login_action.cfm没有适当身份验证的情况下阻止访问其他页面的代码:

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

现在我创建了一个注册页面.此页面不需要身份验证.每个人都应该只需点击一下即可访问该页面,但现在无法登录.我可以通过某种方式检查方法的targtedPage参数来改变它onRequestStart吗?

有人能帮我吗?

use*_*373 6

题:

我可以通过onRequestStart方法的targtedPage(sic)参数来检查吗?

回答

是.

使用现有的代码结构并假设调用注册页面,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>
Run Code Online (Sandbox Code Playgroud)