473,503 Members | 2,150 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Safe Response.Redirect?

If I have two webforms, form1.aspx and form2.aspx, and I want to do a
Response.Redirect from form1 to form2, I can write

Response.Redirect("form2.aspx")

However, if somebody changes the name of form2, the redirect will no
longer work. I could write

Response.Redirect(GetType(form2).Name + ".aspx")

but this is quite ugly and will still not work i.e. if the form2 is
being moved to a sub folder. Worse, I'll only detect it at runtime and
get no compiler warning or such. Compared to winforms, when I'm writing

Dim f as New Form1
f.ShowDialog

if I now change the name of the Form1 class, or the namespace, I will
get a compiler warning.

Is there any "safe" possiblity of redirecting to another webform which
doesn't rely on the physical name and location of an aspx file, and
could be detected at compile time?

Perhaps I'm missing something obvious here...

Thanks for any help
Urs
Nov 19 '05 #1
10 2758
Moving from Windows to Web leads to a lot of these questions. I dont belive
there is a way of doing what you want without storing the file(page) names
ans paths in a datastore.
Nov 19 '05 #2
Josh wrote:
Moving from Windows to Web leads to a lot of these questions. I dont belive
there is a way of doing what you want without storing the file(page) names
ans paths in a datastore.

even if you do that, when somebody renames a page without syncing the
change in the datastore, you're out of luck... :-(
Nov 19 '05 #3
Urs Eichmann wrote:
If I have two webforms, form1.aspx and form2.aspx, and I want to do a
Response.Redirect from form1 to form2, I can write

Response.Redirect("form2.aspx")

However, if somebody changes the name of form2, the redirect will no
longer work. I could write

Response.Redirect(GetType(form2).Name + ".aspx")

but this is quite ugly and will still not work i.e. if the form2 is
being moved to a sub folder.


and it might not even work in the "normal" case: File "Default.aspx"
uses a classname of "_Default". The filename doesn't *need* to be the
same as the classname.

Hans Kesting
Nov 19 '05 #4

"Urs Eichmann" <ur***@online.nospam> wrote in message
news:%2*****************@TK2MSFTNGP10.phx.gbl...
If I have two webforms, form1.aspx and form2.aspx, and I want to do a
Response.Redirect from form1 to form2, I can write

Response.Redirect("form2.aspx")

However, if somebody changes the name of form2, the redirect will no
longer work. I could write

If it is something that is going to change you could put a key in your
web.config file and get the key in the redirect. That way it would be easier
to modify.

Mike

Nov 19 '05 #5

If it is something that is going to change you could put a key in your
web.config file and get the key in the redirect. That way it would be easier
to modify.


Mike,
the problem with this and also the datastore approach of Josh is that
you always have to to changes in *two* locations (change file name and
web.config, or change file name and datastore). This is very
error-prone, compared to the winforms approach I wrote about in my
initial post, where you change the form name *once* and you will be
automatically reminded by the compiler if you forget to change it
anywhere else.

I know this might sound ridiculous to some, but in my code I always
program things in just *one* place so I can never run into sync
problems. It disturbs me that there seems to be no way to do it in this
case.

Urs

Nov 19 '05 #6
> problems. It disturbs me that there seems to be no way to do it in this
case.


You'll find many issues like this in the Web's Stateless environment.
However you caould always write a checking routine as a Visual Studio
Add-In. There might even be one you can download.
Nov 19 '05 #7
Hi Urs,

Yes, the problem you mentioned is the existing limitation of web page based
application. In fact, web application started from pure page based
techniques such as ASP, PHP which only have pages (contains scripts) in
webserver's virtual directory and there are even no class or codebehind
concepts at that time. The ASP.NET encaspulate the dynamic web page's
processing and provide such as webform framework, make the web page
developing most like desktop form developing. However, the fundamental
mechanism is still page/file/directory based, the vritual path rules is
very critical for such application.

In addition, as for using web.config/datastore to store the page name, we
still need to change two places when the page file changes , this is also
limited by the fact that webform page file is not directly 1:1 associated
with page class. Multi aspx page can associated with the same code behind
class and their name can vary.

Anyway, I still think using web.config to store the key/value pair is a
reasonable approach currently.

Thanks,

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 19 '05 #8
Steven,
Thanks for you response. Let's say I have form1.aspx and form2.aspx.
From the codebehind of form1.aspx, is there a way to get the aspx file
name and path of form2? I mean something such as

Sub DoRedirectToForm2()
Dim f as new form2
dim path as string = f.GetRelativeFileAndPath()
f.dispose
response.redirect(path)
end sub

GetRelativeFileAndPath would be a function which retrieves the ASPX file
name and path relative to the path of the current page. Is there such a
function, or a way to get this information? With this, we could do a
redirect without depending on hardcoded file names.

Regards,
Urs

Steven Cheng[MSFT] wrote:
Hi Urs,

Yes, the problem you mentioned is the existing limitation of web page based
application. In fact, web application started from pure page based
techniques such as ASP, PHP which only have pages (contains scripts) in
webserver's virtual directory and there are even no class or codebehind
concepts at that time. The ASP.NET encaspulate the dynamic web page's
processing and provide such as webform framework, make the web page
developing most like desktop form developing. However, the fundamental
mechanism is still page/file/directory based, the vritual path rules is
very critical for such application.

In addition, as for using web.config/datastore to store the page name, we
still need to change two places when the page file changes , this is also
limited by the fact that webform page file is not directly 1:1 associated
with page class. Multi aspx page can associated with the same code behind
class and their name can vary.

Anyway, I still think using web.config to store the key/value pair is a
reasonable approach currently.

Thanks,

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 19 '05 #9
Steven,
Thanks for you response. Let's say I have form1.aspx and form2.aspx.
From the codebehind of form1.aspx, is there a way to get the aspx file
name and path of form2? I mean something such as

Sub DoRedirectToForm2()
Dim f as new form2
dim path as string = f.GetRelativeFileAndPath()
f.dispose
response.redirect(path)
end sub

GetRelativeFileAndPath would be a function which retrieves the ASPX file
name and path relative to the path of the current page. Is there such a
function, or a way to get this information? With this, we could do a
redirect without depending on hardcoded file names.

Regards,
Urs

Steven Cheng[MSFT] wrote:
Hi Urs,

Yes, the problem you mentioned is the existing limitation of web page based application. In fact, web application started from pure page based
techniques such as ASP, PHP which only have pages (contains scripts) in
webserver's virtual directory and there are even no class or codebehind
concepts at that time. The ASP.NET encaspulate the dynamic web page's
processing and provide such as webform framework, make the web page
developing most like desktop form developing. However, the fundamental
mechanism is still page/file/directory based, the vritual path rules is
very critical for such application.
In addition, as for using web.config/datastore to store the page name, we still need to change two places when the page file changes ,
this is also limited by the fact that webform page file is not directly
1:1 associated with page class. Multi aspx page can associated with the
same code behind class and their name can vary. Anyway, I still think using web.config to store the key/value pair is a reasonable approach currently. Thanks,

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no rights.)

Nov 19 '05 #10
Hi Urs,

Thanks for your reply. As for the
====================
is there a way to get the aspx file
name and path of form2? I mean something such as

Sub DoRedirectToForm2()
Dim f as new form2
dim path as string = f.GetRelativeFileAndPath()
f.dispose
response.redirect(path)
end sub
====================

I'm afraid this is not possible in web application environment. As I've
mentioned in the former message , web application are all page based, and
the Page Class in asp.net is just simulating the program model in desktop
applicaiton, but the main actor in web application is still page. Also, the
aspx page file and .cs code behind class is not always 1:1 mapped.
Sometimes, we can use one single codebehind class for multi aspx pages,
other times some aspx page may even not use codebeind class(directly
embeded code in aspx ). That's why we can't retrieve the aspx page file's
name and location dynamically at runtime.

Thanks & Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)







Nov 19 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3886
by: Paul | last post by:
I'm not getting the results I want when I use Response.Redirct in a ASP page. I enter this line of code in a asp page from domain1.com. Response.Redirect...
4
3040
by: JC | last post by:
Hi, I have a simple question regarding the Response.Redirect method. Does the server stop processing the ASP code as soon as it encounters the Redirect command? Or does it ever continue to...
4
14595
by: TomT | last post by:
Hi.. I'm redirecting users to another page using: response.redirect("newpage.asp") this works... But I need to add a variable to the page specified.. IE: newpage.asp?id=JobID
6
4299
by: Sam | last post by:
I have some issues with HTTP Headers and I was hoping for some pointers or references to good articles. Here is the problem. I have 6 .aspx pages, each page contains a common .ascx. This ascx...
3
818
by: Sehboo | last post by:
On my ASP page, when I click a button, I want to do three things: 1. Check for some values. 2. Open a new window and pass some values as query string. 3. Redirect to some other page Here...
13
4669
by: Tim | last post by:
Hello, Is there a way to "cancel" a response.Redirect? For example, in the code below, could I insert anything in the Catch statement that would cancel the redirect and resume flow after the...
5
4545
by: venner | last post by:
I'm having an issue with an ASP.NET website after upgrading to ASP.NET 2.0. The website makes use of a central authentication service (CAS) provided at the university I work for. Each page checks...
4
11385
by: mike.biang | last post by:
I have an ASP page that is using an XMLHTTP object to request various pages from my server. I keep a single session throughout the XMLHTTP requests by bassing the ASPSESSIONID cookie through the...
9
4330
by: RN1 | last post by:
When a server encounters the line Response.Redirect("abcd.asp") in a ASP script, the server tells the browser that it has to be redirected to another page (which is abcd.asp, in this case)....
0
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7287
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
7349
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7008
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...
0
7467
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5022
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3177
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1521
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
399
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.