Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 redirect all pages of my web application

Author  Topic 

maxim
Yak Posting Veteran

51 Posts

Posted - 2006-11-17 : 09:13:39
Version: .net 1.1

If i want to work all night in my online application, it's possible to make all the pages redirect to an "unavaileble.aspx" page quickly and easy?

I wrote this code in global.asax

Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
' Fires when the session is started
Response.Redirect("unavailable.aspx")
End Sub



It worked, but only first time that i'm viewing my page:

After I go to "unavailable.aspx" page if i write ".../otherpage.aspx" i will go to "otherpage.aspx"

How can i prevent this?

Thanks,
Max

Kristen
Test

22859 Posts

Posted - 2006-11-17 : 09:18:08
Dunno about .NET, but can you change IIS to use a different root folder, which only has unavaileble.aspx in it - and make that the default DOC?

Then you can have a SubDomain (e.g. test.MyDomain.com) pointing at the "proper" root folder, and carry on developing in there - provided your hrefs are "/MyPath/MyFile.asp" rather than "www.MyDomain.com/MyPath/MyFile.asp"

Kristen
Go to Top of Page

MichaelP
Jedi Yak

2489 Posts

Posted - 2006-11-17 : 12:54:45
Do you use forms authentication? If so you could modify your web.config to point the users at a "site down" page instead of the login page.

If not, I'd suggest adding a <appSettings> to your Web.config so that you can have a "maintenence" parameter. Then, in the base class that all of your pages inherit from, test for that parameter and send the user to the proper page as needed.

Let me know if you need some more details.

Michael

<Yoda>Use the Search page you must. Find the answer you will. Cursors, path to the Dark Side they are. Avoid them, you must. Use Order By NewID() to get a random record you will.</Yoda>

Opinions expressed in this post are not necessarily those of TeleVox Software, inc. All information is provided "AS IS" with no warranties and confers no rights.
Go to Top of Page

maxim
Yak Posting Veteran

51 Posts

Posted - 2006-11-17 : 14:17:50
quote:
Originally posted by Kristen

Dunno about .NET, but can you change IIS to use a different root folder, which only has unavaileble.aspx in it - and make that the default DOC?



I don't have acess to manage iis! But thanks anyway!

----------------

quote:
Originally posted by MichaelP
If not, I'd suggest adding a <appSettings> to your Web.config so that you can have a "maintenence" parameter. Then, in the base class that all of your pages inherit from, test for that parameter and send the user to the proper page as needed.



Thanks Michael, i think i understand the idea...
but make each postback or page load consult web.config file and see if this paremeter exists doesn't make my application slower?

Thanks!
Max
Go to Top of Page

MichaelP
Jedi Yak

2489 Posts

Posted - 2006-11-17 : 14:27:02
I agree that you would take a performance hit with this, but I would think that it would be negligible. If you had hundreds of hits per second it may be a different story, but I would think for most sites You'd be hard pressed to see a measurable performance differenece.

Handling this at the IIS level would be the "most performant" but without that, you've got to work within the confines of .Net. I think this solution would be fairly easy to impliement and not be too complicated to support.

Michael

<Yoda>Use the Search page you must. Find the answer you will. Cursors, path to the Dark Side they are. Avoid them, you must. Use Order By NewID() to get a random record you will.</Yoda>

Opinions expressed in this post are not necessarily those of TeleVox Software, inc. All information is provided "AS IS" with no warranties and confers no rights.
Go to Top of Page

DustinMichaels
Constraint Violating Yak Guru

464 Posts

Posted - 2006-11-17 : 14:35:43
You could try putting the code you have in the BeginRequest event of the Global.ashx page.

You would need to make sure that the user isn't going to unavailable.aspx first or you will end up causing an infinite loop of redirects.
Go to Top of Page

MichaelP
Jedi Yak

2489 Posts

Posted - 2006-11-17 : 14:44:41
I guess you could also drop this variable into the Application variables upon Application Start like Dustin Suggests. Then you'd not have that Disk hit each time.

Michael

<Yoda>Use the Search page you must. Find the answer you will. Cursors, path to the Dark Side they are. Avoid them, you must. Use Order By NewID() to get a random record you will.</Yoda>

Opinions expressed in this post are not necessarily those of TeleVox Software, inc. All information is provided "AS IS" with no warranties and confers no rights.
Go to Top of Page

snSQL
Master Smack Fu Yak Hacker

1837 Posts

Posted - 2006-11-17 : 17:24:17
Try this in your global.asax

protected void Application_BeginRequest(Object sender, EventArgs e)
{
if (System.Configuration.ConfigurationSettings.AppSettings["MaintenanceMode"] == "true")
{
if (Request.ApplicationPath + "/" + System.Configuration.ConfigurationSettings.AppSettings["MaintenancePage"] != Request.Path)
{
Response.Redirect(System.Configuration.ConfigurationSettings.AppSettings["MaintenancePage"]);
}
}
}

and this in your web.config (put it right before the opening <system.web> tag.

<appSettings>
<add key="MaintenanceMode" value="true" />
<add key="MaintenancePage" value="unavailable.aspx" />
</appSettings>
Go to Top of Page

maxim
Yak Posting Veteran

51 Posts

Posted - 2006-11-17 : 18:36:32
Thank You All!

Its strange! With the code that snSQL gave me i have a loop!
Even when i comment the "if" lines and just writte "response.redirect("unavailable.aspx")" i still have a loop.

It's very strange! I have a forum, and when a guest enter in my site it is redirect to login page but just to clear my doubts i comment this line and i still have a loop!

Maybe I have more than one request when page starts and this is making a conflit

All my pages Inherits from my PageForum Class,
If i want to put this redirect command in this class where should i put it ?
I've tried this:


Private Sub PortalPage_Load(ByVal sender As Object, ByVal e As EventArgs)

Response.Redirect("unavailable.aspx")
'if this works i'll put here the code for read the web.config

If Context.User.Identity.IsAuthenticated Then
If Not (TypeOf context.User Is SitePrincipal) Then
Dim newUser As New SitePrincipal(Context.User.Identity.Name)
Context.User = newUser
End If
End If
End Sub



But i receive an error... maybe "PortalPage_Load" isn't the correct place to put this redirect!
Any ideas about where can i put this?

Thanks one more time for the patiente!

Max
Go to Top of Page
   

- Advertisement -