UrlRewriting - how + where to do the redirect calculations

J

Jon Maz

Hi All,

I'm doing UrlRewriting based on the model in Scott Mitchell's article "URL
Rewriting in ASP.NET".
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/urlrewriting.asp.

In this article the logic for rewriting URLs is contained in Regular
Expressions in the web.config file, like this:
<RewriterConfig>
<Rules>
<RewriterRule>
<LookFor>~/(\d{4})/Default\.aspx</LookFor>
<SendTo>~/ShowBlogContent.aspx?year=$1</SendTo>
</RewriterRule>
</Rules>
</RewriterConfig>

What I like about this approach is that you can change the web.config file
using a text editor and these changes are reflected in the site *without*
having to recompile any dll's.

However (partly because my Regular Expression knowledge isn't that good) I'd
like to do some of the rewriting logic via some plain old C# functions - but
(and here's the tricky bit) still *without* having to recompile.

Can anyone suggest any ways this might be done?

TIA,

JON
 
G

Guest

hi.
try storing the values in the DB. so you can modify them without having to
touch the web.config file. if you make any changes to the web.config file,
you may not have to recompile but the whole web application is being
restarted. so if you are using session objects and application objects, they
are being restarted as well. but making changes to the db will not affect
your application when it comes to server objects.

hope this helps.
 
J

Jon Maz

Hi,

Maybe I didn't explain myself well, but that isn't really what I'm after...
I'll try again!

When doing the UrlRewriting, there isn't always going to be a simple 1:1
correlation between a word/sequence of words in the original url and the
..aspx file the url needs to be redirected to. There may be some quite
complicated processing and validation involved.

It's reasonable to ask why I don't just stick this processing in some
classes/functions in a .cs file in amongst the urlRewriting classes... Now
I *could* do that, and in fact right now I don't have any other solution,
but these classes would (of course) be pre-compiled and thus, in my
production setup (shared hosting) a *real* pain to change, as this involves
downloading source files, compiling on local, re-uploading the updated dll's
bla bla bla.

I'm trying to actively minimise the amount of pre-compiled code in my app by
going for inline code instead of code-behind, and this is the spirit behind
my question here. What I'm looking for is a way of writing these
classes/functions that is not pre-compiled (in the same way inline code
pages are not pre-compiled), allowing me to edit these functions on the fly
and not have to recompile with every change...

Hope that makes more sense!

Thanks,

JON
 
G

Guest

exactly..
the values that needs to be changed here are those for "lookfor" and "send
to"; now a class or a compiled function will always loop or do the same
thing, find a match of these two values. what im suggesting is store these
"lookfor" and "sendto" values in the db. they are just string after all. and
when you do regex, it looks for the absolute value of the regex pattern
(which means you can use a variable). and that variable value is the value
you stored from the db....

if still this doesnt work, maybe you can store the values in xml and use
classic asp to process this logic, in classic asp, you can edit and dump them
as you wish without worrying about compiling and stuff...
 
J

Jon Maz

Hi Alan,

Mmm... Maybe you're right that a db could handle this if "lookfor" and
"sendto" were the only variables involved, but I'm facing processing like
(in pseudocode):

Check to see how many articleIDs (11-digit numerics) there are in
the url
if there's one, go to article.aspx
if there's more than one then go to special.aspx

or

if there's an articleType and an articleCategory but no
articleSubcategory (each of which may require a db lookup) in the
url then.....

Your idea of using classic asp sounded more promising, but unfortunately to
get my UrlRewriting to work as I wish I've had to push *all* requests
through the asp.net engine ie in IIS Application Mappings I've put a *
extension which maps to aspnet_isapi.dll. So basically I can't use classic
asp.

Back to square one?

Thanks for the help,

JON
 

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

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top