Redirect after 5 seconds only if bolNeedToRedirect=True ?

J

Jonathan

I want to redirect a vb.net aspx page after 5 seconds only if a variable
bolNeedToRedirect=True. This variable is determined after code sees whether
a person is logged in.

How could I achive this considering the header meta tag for redirecting
can't be switched based on a Boolean variable?
 
J

Jialiang Ge [MSFT]

Hello Jonathan,

There are several ways to redirect the users to another page:

Category A: redirect with html client side code:
http://vancouver-webpages.com/META/FAQ.html#redirect
A1. Location Http header
A2. Refresh meta tag
A3. <body onload="document.location='http://other.org/'">

e.g.

<SCRIPT LANGUAGE="JavaScript">
redirTime = "2";
redirURL = "http://www.microsoft.com";
function redirTimer() { self.setTimeout("self.location.href =
redirURL;",redirTime); }
</script>
<body onLoad="redirTimer()">

Category B: redirect with server side code:
e.g Response.Redirect("Otherpage.aspx");

To accomplish task that the page is redirected after 5 seconds if the user
logs in, we can do it in this way:

protected void Page_Load(object sender, EventArgs e)
{
if ( // pass login check )
{
Response.Write("<script>redirTimer();</script>"); // call the
javascript to redirect the page
// or
Response.Redirect("Otherpage.aspx"); // redirect with server side
code.
}
}

Hope it helps.

Regards,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
For MSDN subscribers whose posts are left unanswered, please check this
document: http://blogs.msdn.com/msdnts/pages/postingAlias.aspx

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications. If you are using Outlook Express/Windows Mail, please make sure
you clear the check box "Tools/Options/Read: Get 300 headers at a time" to
see your reply promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

Jialiang Ge [MSFT]

Thank you, Mark. That is indeed a good point.

Hello Jonathan, I am sorry that I made a mistake in <SCRIPT
LANGUAGE="JavaScript">. This is a deprecated syntax as Mark said, and
please use
<script type="text/javascript"> instead.

Thanks
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

=================================================
When responding to posts, please "Reply to Group" via your newsreader
so that others may learn and benefit from your issue.
=================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

Jialiang Ge [MSFT]

Hi Jonathan,

I am writing to check the status of the issue. Would you mind letting me
know the result of the suggestions? If you need further assistance, feel
free to let me know. I will be more than happy to be of assistance.

Have a great day!

Regards,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================
 
J

Jonathan

Thanks. I haven't tried it yet but:

a) I don't want any JavaScript since some people might have it disabled

b) Do you know what the VB.net code would be for the conditional timed
redirect? I appreciate that you gave me C# but I have been programming in
VB.net.

TIA
 
J

Jialiang Ge [MSFT]

Hello Jonathan,

"Delayed" page redirecting is a client side happening. Server side code is
not able to control when to redirect the page directly. It needs to write
some javascript code to client side, and let the client code finish the
redirecting.

The corresponding VB.NET code is:

Response.Write("<script>redirTimer();</script>")

(remove the ';' in the end of the C# code line)

Regards,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================
 
J

Jialiang Ge [MSFT]

Hello Jonathan,

Would you let me know the result of my suggestion of using client-side
script to do the delayed redirection? If you need further assistance,
please feel free to let me know.

Thanks
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

=================================================
When responding to posts, please "Reply to Group" via your newsreader
so that others may learn and benefit from your issue.
=================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top