473,834 Members | 1,874 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

urlMappings interaction with web.config hierarchy

I have an application with the following layout

/root/
/root/Default.aspx
/root/web.config
/root/child/
/root/child/web.config
web.config has a custom configuration section "testSectio n" with the
basic layout of:

<testSection>
<tests>
<add id="" value="" />
</tests>
</testSection>

The root web.config defines:

<testSection>
<tests>
<add id="test1" value="root1" />
<add id="test2" value="root2" />
</tests>
</testSection>

the child web.config defines:

<testSection>
<tests>
<remove id="test2" />
<add id="test2" value="child2" />
<add id="test3" value="child3" />
</tests>
</testSection>

finally, the root web.config defines the url mapping:

<urlMappings enabled="true">
<add url="~/root/child/Default.aspx"
mappedUrl="~/root/Default.aspx"/>
</urlMappings>

Essentially, my goal is, for the url "~/root/child/Default.aspx", I want
to run the file "~/root/Default.aspx" BUT, I want it run as if were
located at "~/root/child/Default.aspx", inheriting the child defined
web.config.

Can someone point me towards the solution? As it is now, the page gets
run as if it were located where it is actually located, and no
web.config accumulation is done. Presumably I either need a way to
manually load configuration files before the Rewrite happens, or I need
a way to execute a .aspx class as if it were located at a different
location. I imagine that the first way is the better way to go, as
everything else (urls etc) should be processed as if the file were
executing at it's actual location.

I just need a starting point. I have written custom url mapping
modules, but nothing I know how to do will allow me to solve my problem.

Thanks in advance,
Luke
Jan 11 '06 #1
2 4757
Luke Dalessandro wrote:
I have an application with the following layout

/root/
/root/Default.aspx
/root/web.config
/root/child/
/root/child/web.config
web.config has a custom configuration section "testSectio n" with the
basic layout of:

<testSection>
<tests>
<add id="" value="" />
</tests>
</testSection>

The root web.config defines:

<testSection>
<tests>
<add id="test1" value="root1" />
<add id="test2" value="root2" />
</tests>
</testSection>

the child web.config defines:

<testSection>
<tests>
<remove id="test2" />
<add id="test2" value="child2" />
<add id="test3" value="child3" />
</tests>
</testSection>

finally, the root web.config defines the url mapping:

<urlMappings enabled="true">
<add url="~/root/child/Default.aspx"
mappedUrl="~/root/Default.aspx"/>
</urlMappings>

Essentially, my goal is, for the url "~/root/child/Default.aspx", I want
to run the file "~/root/Default.aspx" BUT, I want it run as if were
located at "~/root/child/Default.aspx", inheriting the child defined
web.config.

Can someone point me towards the solution? As it is now, the page gets
run as if it were located where it is actually located, and no
web.config accumulation is done. Presumably I either need a way to
manually load configuration files before the Rewrite happens, or I need
a way to execute a .aspx class as if it were located at a different
location. I imagine that the first way is the better way to go, as
everything else (urls etc) should be processed as if the file were
executing at it's actual location.

I just need a starting point. I have written custom url mapping
modules, but nothing I know how to do will allow me to solve my problem.

Thanks in advance,
Luke


Ok,

An update for anyone who cares. I've got this working by using a custom
IHttpHandler. Essentially, I check all incoming requests for existence.
If they exist, I process them normally.

If they don't exist, and a "searchPare nt" flag is set in the
configuration file for the current execution directory, I strip the last
directory from the url, and check for existence. This runs recursively
until I find the file, I hit the application root directory, or I hit a
directory where parent searching isn't enabled.

Just as an aside, to load a web configuration file from a directory
that's not the currently execution directory, use the GetSection(stri ng,
string) version of GetSection, passing the path to the file as the
second parameter. This is necessary because I'm never actually Rewriting
the context url, I'm just doing a directory search.

The magic that happens is that, in the IHttpHandler, the method that I
am using to execute the page is PageParser.GetC ompiledPageInst ance. This
takes three parameters, the first two specify the page to run, and the
third is the context to run in.

By loading the page that I've found, with the context that still lists
the current execution path, the page loads as if it were at the
requested location. Essentially, this is sort of a url rewrite without
changing the context.

Caveats:

I'm not sure if this causes POST problems, or cache strangeness.
I'm still looking into it.

I've found that if I have an actual url rewriting module that
runs before I run this execution file search, I need to pass
"false" as the second parameter to context.Rewrite Path() or Urls
are not resolved correctly by the page. I'm not sure if this is
a RewritePath problem or specific to instantiating a page that
doesn't actually reside where the context thinks it does.

VirtualPathProv ider seems to offer customization potential, but
I haven't been able to figure it out yet.

I'll post any more issues I run into for anyone paying attention. Hope
this helps if you're trying to do something like this.

Luke
Jan 12 '06 #2
Luke Dalessandro wrote:
Luke Dalessandro wrote:
I have an application with the following layout

/root/
/root/Default.aspx
/root/web.config
/root/child/
/root/child/web.config
web.config has a custom configuration section "testSectio n" with the
basic layout of:

<testSection>
<tests>
<add id="" value="" />
</tests>
</testSection>

The root web.config defines:

<testSection>
<tests>
<add id="test1" value="root1" />
<add id="test2" value="root2" />
</tests>
</testSection>

the child web.config defines:

<testSection>
<tests>
<remove id="test2" />
<add id="test2" value="child2" />
<add id="test3" value="child3" />
</tests>
</testSection>

finally, the root web.config defines the url mapping:

<urlMappings enabled="true">
<add url="~/root/child/Default.aspx"
mappedUrl="~/root/Default.aspx"/>
</urlMappings>

Essentially, my goal is, for the url "~/root/child/Default.aspx", I
want to run the file "~/root/Default.aspx" BUT, I want it run as if
were located at "~/root/child/Default.aspx", inheriting the child
defined web.config.

Can someone point me towards the solution? As it is now, the page gets
run as if it were located where it is actually located, and no
web.config accumulation is done. Presumably I either need a way to
manually load configuration files before the Rewrite happens, or I
need a way to execute a .aspx class as if it were located at a
different location. I imagine that the first way is the better way to
go, as everything else (urls etc) should be processed as if the file
were executing at it's actual location.

I just need a starting point. I have written custom url mapping
modules, but nothing I know how to do will allow me to solve my problem.

Thanks in advance,
Luke


Ok,

An update for anyone who cares. I've got this working by using a custom
IHttpHandler. Essentially, I check all incoming requests for existence.
If they exist, I process them normally.

If they don't exist, and a "searchPare nt" flag is set in the
configuration file for the current execution directory, I strip the last
directory from the url, and check for existence. This runs recursively
until I find the file, I hit the application root directory, or I hit a
directory where parent searching isn't enabled.

Just as an aside, to load a web configuration file from a directory
that's not the currently execution directory, use the GetSection(stri ng,
string) version of GetSection, passing the path to the file as the
second parameter. This is necessary because I'm never actually Rewriting
the context url, I'm just doing a directory search.

The magic that happens is that, in the IHttpHandler, the method that I
am using to execute the page is PageParser.GetC ompiledPageInst ance. This
takes three parameters, the first two specify the page to run, and the
third is the context to run in.

By loading the page that I've found, with the context that still lists
the current execution path, the page loads as if it were at the
requested location. Essentially, this is sort of a url rewrite without
changing the context.

Caveats:

I'm not sure if this causes POST problems, or cache strangeness.
I'm still looking into it.

I've found that if I have an actual url rewriting module that
runs before I run this execution file search, I need to pass
"false" as the second parameter to context.Rewrite Path() or Urls
are not resolved correctly by the page. I'm not sure if this is
a RewritePath problem or specific to instantiating a page that
doesn't actually reside where the context thinks it does.

VirtualPathProv ider seems to offer customization potential, but
I haven't been able to figure it out yet.

I'll post any more issues I run into for anyone paying attention. Hope
this helps if you're trying to do something like this.

Luke


Update:

This isn't working entirely perfectly. When a url like
"~/root/child/Default.aspx" is processed by "~/root/Default.aspx"
without RewritingPath, almost everything is exactly right. Urls are
based on "~/root/child/" correctly, and calls to
WebConfiguratio nManager.GetSec tion("custom") all reflect the web.config
file at "~/root/child/web.config" like I want.

The problem is that NON-custom web.config configuration data is coming
from "~/root/web.config". For instance, if I have a <pages
masterPathFile= "root.maste r" theme="root" /> declared at the "~/root/"
level, and a <pages masterPathFile= "child.mast er" theme="child" />
declared at the child level, the page is displaying the root
theme/master rather than the child theme/master, as I want it to (this
is for an execution directory of "~/root/child/Default.aspx").

I don't understand why, if my custom configuration sections are
available via GetSection("cus tom") without a path parameter, the page
wouldn't be seeing the built-in configuration sections from the same
web.config.

If anyone's following this I could use some help. I can work around this
for now by defining a custom configuration section where I can specify
my own themes/masters, and then putting custom theme/master loading code
in a default page class base, but I'm not sure what other functionality
I need in the future (things like access control etc).

Thanks,
Luke
Jan 13 '06 #3

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

Similar topics

22
3023
by: Daniel Billingsley | last post by:
Ok, I wanted to ask this separate from nospam's ridiculous thread in hopes it could get some honest attention. VB6 had a some simple and fast mechanisms for retrieving values from basic text files, which in turn could be simply and easily maintained with notepad. I understand the benefits of XML, really, but in the case of configuration files it seems it is almost always nothing more than unnecessary complexity, both in accessing them...
3
1395
by: Razak | last post by:
Hello, I'm new with ASP.NET. I've seen samples which has custom 'entry' in Web.Config which works well. But when I enter my 'entry', it produces app error: The entry is like below:- <?xml version="1.0" encoding="utf-8" ?> <configuration> <myAspApp>
1
1571
by: Peter Larsson | last post by:
I'm testing the 2.0 Beta, I'm using Visual Web Developer Express Edition, running on windows 2000 server. When I run my site with the built in web-server the UrlMappings work great, but when I run them in IIS they only give me 404:s. <system.web> <urlMappings enabled="true"> <!--Mappade "statiska sidor"--> <add mappedUrl="~/Default.aspx" url="~/Index.html" />
1
1641
by: jazzMan007 | last post by:
Hi All - I'm using the new UrlMappings feature in an ASP.NET 2.0 application. I'm using the unique urls, mapped to shared files, in the site map. So for example, I have pages A, B, & C...all of which direct to a subpage, D. The sitemap requires URLs to be unique, so to make sure the navigation works, I've mapped AD, BD, & CD to D using the urlMappings section in the web.config file. So that all works fine an dandy. Now I'm working on...
0
1248
by: Rune B | last post by:
Hey Group Why does this urlMapping work just fine on the development webserver, but not at the IIS (6.0) ? <urlMappings enabled="true"> <add url="~/srs" mappedUrl="~/Page.aspx?NodeID=1234&ect..." /> </urlMappings> it reacts just fine whem I try to access http://localhost:1234/testsite/srs
9
3603
by: gerry | last post by:
Is there any way to prevent web.config inheritance in nested web applications ? Here is the scenario, a 3rd party asp.net web application installed on an asp.net intranet site : http://intranet.company.org http://intranet.company.org/3rdPartApp both are configured as applications in IIS. the subapp is not physcially installed beneath root app
0
1121
by: Bill | last post by:
On an ASP.NET 2.0 server, is there a way I can use urlMappings with Classical ASP pages? The web.config file, in my web root, is this: <?xml version="1.0" ?> <configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0"> <system.web> <customErrors mode="Off"/> <urlMappings enabled="true"> <add url="/test1/foo1.asp" mappedUrl="/test2/foo2.asp" />
1
1546
by: Nathan Sokalski | last post by:
I am using the <urlMappingselement in my Web.config file as follows: <urlMappings enabled="true"> <add url="~/worldnews.aspx" mappedUrl="~/viewlinks.aspx?category=World+News&section=Main"/> </urlMappings> Visual Studio 2005 has &section
10
2065
by: eagle | last post by:
I have a web.config in my application that contains the connection strings to all my datasources. I want to move these connection strings to another web config up the folder hierarchy so that all my apps can use the same connection strings. That is supposed to be how it's done, no? Instead of the web.config being in c:\inetpub\wwwroot\myApp\web.config, I have it in c:\inetpub\wwwroot\web.config. However, I get an "Object reference not...
0
9799
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9646
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10793
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10510
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9331
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7758
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6954
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4427
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 we have to send another system
2
3978
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.