PDA

View Full Version : Two pages, same name, different folders


CheekyTinker
06-12-2005, 09:28 AM
Hi

I have two pages with the same name, News.aspx, one in the root of my application, one in an Admin subfolder, accessed as follows:

www.mydomain.com/news.aspx

www.mydomain.com/admin/news.aspx

The problem I'm encountering is that I can only access which ever one appears last in my web.config. i.e. if I navigate to .../news.aspx then navigate to .../admin/news.aspx I get the .../news.aspx page being display on both occasions...even though the browser address control correctly shows the appropriate path.

My object definitions in the web.config for each page are as follows:


<object name="admin_news" type="~/Admin/News.aspx" parent="list">
</object>

<object name="news" type="News.aspx" parent="ShopFront">
</object>


As a workaround I'm going to rename one of the pages, but should the above be possible? My Admin folder is not a virtual directory as I'm not able to set them up with my hosting company.

Thanks in advance for any help.

Aleks Seovic
06-17-2005, 10:00 AM
You need to use hierarchical contexts in this case and define admin news page within web.config in your admin directory.

I saw another of your posts where you had a problem getting hierarchical contexts to work properly, so the following should address that issue as well.

This is sample root Web.config:


<?xml version="1.0" encoding="utf-8" ?>
<configuration>

<configSections>
<sectionGroup name="spring">
<section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core"/>
<section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core"/>
</sectionGroup>
</configSections>

<spring>

<context type="Spring.Context.Support.WebApplicationContext, Spring.Web">
<resource uri="config://spring/objects"/>
</context>

<objects>

<object type="News.aspx"/>

</objects>

</spring>

<system.web>

<httpHandlers>
<add verb="*" path="*.aspx" type="Spring.Web.Support.PageHandlerFactory, Spring.Web"/>
<add verb="*" path="*.asmx" type="Spring.Web.Services.WebServiceHandlerFactory, Spring.Web"/>
</httpHandlers>

...

</system.web>

</configuration>


And here is the sample Web.config within your admin directory:


<?xml version="1.0" encoding="utf-8" ?>
<configuration>

<spring>

<context type="Spring.Context.Support.WebApplicationContext, Spring.Web">
<resource uri="config://spring/objects"/>
</context>

<objects>

<object type="News.aspx"/>

</objects>

</spring>

</configuration>


As you can see, all you need within child context definition is context definition and object definitions. I tried this example and it works properly -- I didn't have the problem you encountered with first accessed page always being returned.

Let me know if this helps.

Later,

Aleks

billyy
02-13-2007, 08:14 PM
Hi, I am also encountering the similar problem. And I saw hierarchical contexts would be the solution. But my personal preference would be to put all difinitions of pages into one central location, so the page flow could be more intuitive and easier to manage here. Do you any plan to support that later?

Erich Eichinger
02-13-2007, 11:38 PM
Hi,

in short: yes. It's actually one of our open JIRA issues SPRNET-389 (http://opensource.atlassian.com/projects/spring/browse/SPRNET-389).

At the moment only the page's filename is used as object-id. This id will change to using the full virtual path of the page.

cheers,
Erich

bjornwang
02-15-2007, 11:59 AM
See also my thread on the same subject:
http://forum.springframework.net/showthread.php?t=1611

Changing to local Web.config files does not work well for me because this introduces new problems, namely unstable dependancy injection on the two first pageloads.

This does not seem to be an issue when configuring .aspx-files in a file (which is my preference also), but this of course introduces the naming-problem instead.
Am I right to assume that configuration in Web.config files are somehow bound later than configuration loaded from files?

Erich, check out my two last post in that tread for more information.

Erich Eichinger
02-15-2007, 01:48 PM
Hi,

Am I right to assume that configuration in Web.config files are somehow bound later than configuration loaded from files?

No. Objectdefinitions are parsed. created and merged in order of their appearence within the <context> section. E.g.


<spring>
<context>
<resource uri="assembly://myassembly/Namespace/assemblyobjects.xml" />
<resource uri="web://~webobjects.xml" />
<resource uri="config://spring/sectionobjects" />
</context>
</spring>


will parse object definitions in order assemblyobjects.xml, webojbects.xml and sectionobjects.xml (possibly overriding already existing definitions!). After parsing and creating all definitions, singletons get instantiated.

@bjorn: I'm really sorry - I've been thinking a lot about your problem, but have no idea, why it doesn't work for you. Maybe you could produce a DEBUG-log file and email me?

cheers,
Erich

bjornwang
02-16-2007, 11:21 AM
Hello Erich,

First of all: I'm very thankful for the kind interest that both you and Mark has taken in my problems with Spring. While I'm hugely impressed with Spring, your helpful support is what really makes the project shine for me. Your helpful advice is very much appreciated.

For my problem, I've narrowed it down to how the CMS we're using handles URL-rewrites to produce friendly URLs. Thus, my problem should have no bearing for CheekyTinker's problem.

I've started a separate thread for this problem:
http://forum.springframework.net/showthread.php?p=5382#post5382