homepage Welcome to WebmasterWorld Guest from 204.236.255.69
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Visit PubCon.com
Home / Forums Index / Microsoft / Microsoft IIS Web Server and ASP.NET
Forum Library, Charter, Moderators: ocean10000

Microsoft IIS Web Server and ASP.NET Forum

    
301 rewrite problems in global.asa
spiral




msg:3997673
 1:37 pm on Sep 29, 2009 (gmt 0)

I've never done 301s in asp, always worked with .htaccess and things were good.

Currently need to redirect a whole site to the root of a new site (sitewide to root). I only have FTP access to the server. Site is old asp site using some sort of cms.

I tried the below code and got an error message:
<%
Response.Status="301 Moved Permanently"
Response.AddHeader "Location", "myNewSite.com"
%>

This is my global.asa file:

<SCRIPT LANGUAGE=VBScript RUNAT=Server>

Sub Application_OnStart

End Sub

Sub Application_OnEnd
'nothing needed here for this example
End Sub

Sub Session_OnStart
Application.lock
Application("ActiveUsers") = Application("ActiveUsers") + 1
Application.unlock
End Sub

Sub Session_OnEnd
Application.lock
Application("ActiveUsers") = Application("ActiveUsers") - 1
Application.unlock
End Sub

</SCRIPT>

Can anyone please, please post the modified code for a 301? Also, I'm new to developing, and not sure about line breaks in all the asp code snippets I see online.

 

Ocean10000




msg:3997686
 1:51 pm on Sep 29, 2009 (gmt 0)

<SCRIPT LANGUAGE=VBScript RUNAT=Server>

Sub Application_OnStart

End Sub

Sub Application_OnEnd
'nothing needed here for this example
End Sub

Sub Session_OnStart
Application.lock
Application("ActiveUsers") = Application("ActiveUsers") + 1
Application.unlock

Response.Status="301 Moved Permanently"
Response.AddHeader "Location", "myNewSite.com"
End Sub

Sub Session_OnEnd
Application.lock
Application("ActiveUsers") = Application("ActiveUsers") - 1
Application.unlock
End Sub

</SCRIPT>

spiral




msg:3997704
 2:09 pm on Sep 29, 2009 (gmt 0)

Thanks for the code Ocean, but it's not working for me.

I pasted as above, only change was my real URL. It worked once, then stopped.

Ocean10000




msg:3997900
 6:02 pm on Sep 29, 2009 (gmt 0)

<SCRIPT LANGUAGE=VBScript RUNAT=Server>

Sub Application_OnStart

End Sub

Sub Application_OnEnd
'nothing needed here for this example
End Sub

Sub Session_OnStart
Application.lock
Application("ActiveUsers") = Application("ActiveUsers") + 1
Application.unlock

Response.Status="301 Moved Permanently"
Response.AddHeader "Location", "myNewSite.com"
'Destroys the Session. So that future calls will retrigger this code.
Session.Abandon
'Sends buffered output immediately.
Response.Flush
'Stops processing the .asp file and returns the current result.
Response.End
End Sub

Sub Session_OnEnd
Application.lock
Application("ActiveUsers") = Application("ActiveUsers") - 1
Application.unlock
End Sub

</SCRIPT>

References
Response Object [msdn.microsoft.com]

Session Object [msdn.microsoft.com]

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Microsoft / Microsoft IIS Web Server and ASP.NET
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved