我在onRequestStart
Application.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
吗?
有人能帮我吗?
题:
我可以通过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)