Is there a compile-time checked way of redirecting to a page?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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 are redirecting to somewhere that
doesn't exist.

Worse, if you do type it correctly, but then later the page name changes or
the page moves, you still won't find out until run time.

I have a framework that solves this problem and guarantees, at compile time,
that all redirect attempts to other pages in the web project are valid. I
like it very much. Unfortunately, ASP 2.0 trods all over the solution in a
number of ways and my sites don't even compile in the new framework. So,
before I try to cram my solution (very uncomfortably) into ASP 2.0, I'd like
to know if there is any other well-known solution to this problem.

Thank you.

Greg Smalter
 
No. How could there be? You could be redirecting to absolutely any site any
site on the internet. How could the compiler know which addresses are valid
and which are not.
 
There is. Obviously there have to be constraints, and the one I put forth is
that it is to another page within the same web project.
 
I suppose they could have written something like that, but I think in most
cases it is not all that useful. A spelling mistake like this isn't all that
common, and is usually caught early on if it happens (this is pretty rare).
At least in my experience and from the experiences I've seen with others.

You said you already wrote your own solution - why does 2.0 prevent you from
using it?
 
I like to keep a list of my pages in a static class somewhere so that
this does not happen.

public abstract class Pages
{
public const string UserManage = "/Applications/UserManage.aspx";
public const string UserEdit = "/Applications/UserEdit.aspx";
public const string UserDelete = "/Applications/UserDelete.aspx";
public const string Index = "/Index.html";
}


Response.Redirect(Pages.UserManage, true);


This way, all potential typos are sitting next to each other in a
single file. If you refer to a page by the wrong name anywhere else,
it's a compile-time error.

Good luck!

Jason Kester
Expat Software Consulting Services
http://www.expatsoftware.com/
 

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

Back
Top