470,810 Members | 1,433 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,810 developers. It's quick & easy.

Page Redirecting

Hi,

I'm trying to do something in global.asax that I would have thought to
be quite simple. Basically, any request at all should get sent to
another page. I actually got the code below from a book. For some
reason, it's not working.

Can someone please tell me what I'm doing wrong?

Thanks in advance,
Damien

protected void Application_BeginRequest(object sender,
EventArgs e)
{
// this causes a "redirect loop"
Response.Redirect(Request.ApplicationPath + "/Forms/
LoginPage.aspx");

// This just "doesn't work" - standard page loads.
Context.RewritePath(Request.ApplicationPath + "/Forms/
LoginPage.aspx");
}
Jun 27 '08 #1
4 2648
da**********@yahoo.com.au wrote:
Hi,

I'm trying to do something in global.asax that I would have thought to
be quite simple. Basically, any request at all should get sent to
another page. I actually got the code below from a book. For some
reason, it's not working.

Can someone please tell me what I'm doing wrong?

Thanks in advance,
Damien

protected void Application_BeginRequest(object sender,
EventArgs e)
{
// this causes a "redirect loop"
Response.Redirect(Request.ApplicationPath + "/Forms/
LoginPage.aspx");
You have to check if it's the login page that is requested or not. Now
you are redirecting every request, even the ones that you are causing by
redirecting to the login page.
// This just "doesn't work" - standard page loads.
Context.RewritePath(Request.ApplicationPath + "/Forms/
LoginPage.aspx");
}
--
Göran Andersson
_____
http://www.guffa.com
Jun 27 '08 #2
Your "redirect loop" is caused because you are not checking whether the
currently executing page is "LoginPage.aspx"

So even a successful redirect to LoginPage.aspx then redirects to
LoginPage.aspx, and the cycle continues.

I suggest checking the currently loaded page (Request.Url should help).

Otherwise, it might be worth looking at using a built in Authentication
provider like FormsAuthentication or similar to provide this redirect to
login functionality.

Good luck,
BWC

"da**********@yahoo.com.au" wrote:
Hi,

I'm trying to do something in global.asax that I would have thought to
be quite simple. Basically, any request at all should get sent to
another page. I actually got the code below from a book. For some
reason, it's not working.

Can someone please tell me what I'm doing wrong?

Thanks in advance,
Damien

protected void Application_BeginRequest(object sender,
EventArgs e)
{
// this causes a "redirect loop"
Response.Redirect(Request.ApplicationPath + "/Forms/
LoginPage.aspx");

// This just "doesn't work" - standard page loads.
Context.RewritePath(Request.ApplicationPath + "/Forms/
LoginPage.aspx");
}
Jun 27 '08 #3
<da**********@yahoo.com.auwrote in message
news:8d**********************************@s33g2000 pri.googlegroups.com...
Can someone please tell me what I'm doing wrong?
This has already been answered.

However, even if you check whether the current Request.Url contains
"LoginPage.aspx", what then...?

As it stands currently, your users will never be able to proceed any further
than the login page...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jun 27 '08 #4
>As it stands currently, your users will never be able to proceed any further than the login page...

Correct. Sorry - this wasn't the best example. I'm just 'playing
around' to test the functionality.

Out of interest, I got the response.redirect working by ommitting
calls to the login page, however, I can't get the context.rewrite to
happen. Googling around, I found a few posts of people having trouble
with it... none of them which seemed to have answers.

Thanks very much for everyone's help :-)

On Jun 24, 7:28*pm, "Mark Rae [MVP]" <m...@markNOSPAMrae.netwrote:
<damiensaw...@yahoo.com.auwrote in message

news:8d**********************************@s33g2000 pri.googlegroups.com...
Can someone please tell me what I'm doing wrong?

This has already been answered.

However, even if you check whether the current Request.Url contains
"LoginPage.aspx", what then...?

As it stands currently, your users will never be able to proceed any further
than the login page...

--
Mark Rae
ASP.NET MVPhttp://www.markrae.net
Jun 27 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Paul | last post: by
1 post views Thread by craigkenisston | last post: by
4 posts views Thread by shapper | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.