我想让访问者一进入我的站点,就必须浏览我的主页,但是,偏偏有问题......

apple749769 2002-03-23 11:33:54
我在GLOBAL。ASA文件里写着:

<script language=vbscript runat=server>
sub session_onstart
MyHomePage="/default.htm"
RequestPage=Request.ServerVariables("SCRIPT_NAME")
if not(strcomp(MyHomePage,RequestPage,vbTextCompare)=0) then
Response.redirect MyHomePage
end if
end sub
</script>
但是,有两个问题:

1、我还是可以浏览我的站点下一级的网页。你能帮我吗?让访问者一进入我的站点,就必须浏览我的主页。

2、进入主页以后,我点击上面的链接后,它还是回到主页中去了,怎么也进去不了。

有知道答案的兄弟,请帮帮忙。

------------------在线等着您的答复......

Thank you any way!
...全文
56 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
apple749769 2002-03-28
  • 打赏
  • 举报
回复
to flyukeer(飞雪轻扬) :好方法!!我试一试......
apple749769 2002-03-28
  • 打赏
  • 举报
回复
你说得太详细了。我在调试,但

Thank you anyway!!!
flyukeer 2002-03-28
  • 打赏
  • 举报
回复
这个问题只要在其它非主页的页面上加上这样一句
<%
if request.cookies("go_home")="" then
response.redirect "你的主页地址"
end if
%>
在主页上加上这样一句:
<%
response.cookies("go_home")="true"
%>
这样你的上面两个问题都解决了
jamex 2002-03-28
  • 打赏
  • 举报
回复
Session_OnStart
The Session_OnStart event occurs when the server creates a new session. The server processes this script prior to executing the requested page. The Session_OnStart event is a good time for you to set any session-wide variables, because they will be set before any pages are accessed. All the built-in objects (Application,ObjectContext, Request, Response, Server, and Session) are available and can be referenced in the Session_OnStart event script.

Syntax
<SCRIPT LANGUAGE=ScriptLanguage RUNAT=Server>
Sub Session_OnStart
. . .
End Sub

</SCRIPT>

Parameters
ScriptLanguage
Specifies the scripting language used to write the event script. It may be any supported scripting language, such as VBScript or JScript. If more than one event uses the same scripting language, they can be combined under a single set of <SCRIPT> tags.
Example
Although the Session object persists if the Session_OnStart event contains a call to the Redirect or End methods, the server stops processing the script in both the Global.asa file and in the file that triggered the Session_OnStart event.

You can call the Redirect method in the Session_OnStart event, for example, to ensure that users always start a session at a particular Web page. When the user enters the application, the server creates a session for that user and processes the Session_OnStart event script. You can include script in this event to check whether the page opened by the user is the starting page and, if not, direct the user to the starting page by calling the Response.Redirect method. This is demonstrated in the following example.

<SCRIPT RUNAT=Server Language=VBScript>
Sub Session_OnStart
' Make sure that new users start on the correct
' page of the ASP application.

' Replace the value given to startPage below
' with the virtual path to your application's
' start page.

startPage = "/MyApp/StartHere.asp"
currentPage = Request.ServerVariables("SCRIPT_NAME")

' Do a case-insensitive compare, and if they
' don't match, send the user to the start page.

if strcomp(currentPage,startPage,1) then
Response.Redirect(startPage)
end if
End Sub
</SCRIPT>
The preceding example only works for browsers that support cookies. Because a noncookie browser does not return the SessionID cookie, the server creates a new session each time the user requests a page. Thus for each request, the server processes the Session_OnStart script and redirects the user to the starting page. If you use the script below, it is recommended that you put a notice on your starting page to inform users that the site requires a cookie-enabled browser.

Remarks
You should note that any Session_OnStart event script that follows a call to the Redirect method is not executed. For this reason, you should call the Redirect method last in your event script. This is demonstrated in the following example.

<SCRIPT LANGUAGE=VBScript RUNAT=Server>
Sub Session_OnStart
' Session initialization script
Response.Redirect "http:/server/app/StartHere.asp"
End sub
</SCRIPT>
In the preceding example the Redirect method hides any text displayed to the client during the session-initialization script.

jamex 2002-03-28
  • 打赏
  • 举报
回复
sub session_onstart
MyHomePage="/default.asp"
RequestPage=Request.ServerVariables("SCRIPT_NAME")
if not(strcomp(MyHomePage,RequestPage,vbTextCompare)=0) then
Response.redirect MyHomePage
end if
end sub

在session_onstart事件中,如果用redirect的话,服务器就首先会中断(作废)本次的session,然后执行Response.redirect MyHomePage操作。
这是,如果MyHomePage是asp文件的话,再一次触发session_onstart事件,新的session建立成功,从此,连接其他的asp文件时,不再触发session_onstart事件

如果MyHomePage是htm文件的话,不会触发session_onstart事件,所以连接其他的asp文件时,再一次触发session_onstart事件,有重新回到了MyHomePage,如此循环!

haha
jamex 2002-03-28
  • 打赏
  • 举报
回复
调用*.htm文件的话,不会触发session_onstart事件,所以就可以进入
而第一次调用*.asp文件的话,会触发session_onstart事件,所以就转到主页去了
apple749769 2002-03-28
  • 打赏
  • 举报
回复
还是我贴出来的代码,第一次试的时候,我的global.asa好象没执行,但是第二次的时候,就好了,第一个问题的答案就是我贴出来的代码。

现在,我的问题是第二个问题,补充一点:在主页中,如果是连接到*。htm文件就可以进去。而如果是连接到*.asp文件就进去不了,总是重定位到主页里,你知道这是为什么吗?

谢谢你的回答!!!
jamex 2002-03-28
  • 打赏
  • 举报
回复
我试了一下,可能是这样的:
你将
MyHomePage="/default.htm"
改成
MyHomePage="/default.asp"
试一下,这样的话,就行了!你试试.

jamex 2002-03-28
  • 打赏
  • 举报
回复
先将你 解决了的第一个问题的源码贴出来我看看!好吗?
apple749769 2002-03-28
  • 打赏
  • 举报
回复
谢谢各位的回答,谢谢!!!
antshome 2002-03-23
  • 打赏
  • 举报
回复
试试

<script language=vbscript runat=server>
sub session_onstart
MyHomePage="/default.htm"
if session("HOME")="" or session("HOME")<>"true" then
session("HOME")="true"
Response.redirect MyHomePage
end if
end sub
</script>
apple749769 2002-03-23
  • 打赏
  • 举报
回复
看来,大家都去吃饭去了......
julyclyde 2002-03-23
  • 打赏
  • 举报
回复
你的global没有执行吧?
julyclyde 2002-03-23
  • 打赏
  • 举报
回复
你的global没有执行吧?
lanying 2002-03-23
  • 打赏
  • 举报
回复
因该是REFFER那个变量,忘了
apple749769 2002-03-23
  • 打赏
  • 举报
回复
我已经解决了第一个问题,
第二问题是:
进入主页后,如果是链接到*.asp网页,那么还是回到主页。如果是*.htm网页,j就可以进入。

各位,能帮我想一下解决的办法吗?

28,406

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧