473,395 Members | 1,670 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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 2783
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: lozd | last post by:
Would appreciate any solutions people could offer for this. Basically I wan't to use a frameset with an aspx page as the contents rather than a htm page and I'd like to be able to redirect the...
9
by: Paul | last post by:
What I am trying to do is as follows. I have a page with 3 links,that direct the user to 3 different pages when selected after login. So all link selections will first direct the user to a login...
1
by: craigkenisston | last post by:
Hi, I'm going nuts with a supposed simple thing. I have this page : <%@ Page language="c#" Codebehind="404page.aspx.cs" AutoEventWireup="false" Inherits="mydomain._404page" %> <!DOCTYPE HTML...
4
by: Greg Smalter | last post by:
Redirecting from page to page within a web project is pretty easy. However, all Redirect methods take strings as arguments, as if you mistype the string, you don't find out until run time that you...
4
by: deepukutty | last post by:
HI all, I am using IE(Internet Explorer) as my default browser for asp.net application development. Today i faced a strange problem. When ever an exception occured in the page ....application...
4
by: shapper | last post by:
Hello, I am using the following code line in my VB code to redirect to another page inside my web site: Response.Redirect("Message.aspx") I am getting the error: The page isn't redirecting...
1
by: sreekeerthi | last post by:
hi friends...this is keerthi...i am doing a project where i want to redirect my page when ever the back button is clicked...for this i am using window.onbeforeunload method..and for page redirection...
1
by: Itzik | last post by:
The simple situation that works: A form (ASP 2.0 Page) with Page.MaintainScrollPositionOnPostBack set to True as well as Page.EnableViewState defaults to True. As the form's data are submitted to...
1
by: kang jia | last post by:
hi when user entered particulars in signuppage and click" signup" button, i will direct them to do_signup.php. if say the NRIC is dupicate in datebase, i will redirect them back to signup page...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.