Front Controller pattern!

C

Colin Basterfield

Hi,

has anyone (tried to) implement the Front Controller pattern as described at

http://msdn.microsoft.com/architecture/patterns/ImpFrontControllerInASP/

I'm having trouble resolving the controller.mapping section in the
web.config file, as it is used in UrlMap.cs and that is used by
RedirectingCommand.cs in the samples given in the article above.

Does anyone know how this bit is meant to work? The code I have compiled
fails because

private UrlMap map = UrlMap.SoleInstance;

and then

public void Execute(HttpContext context)

{

OnExecute(context);

String tempMap = map.Map[context.Request.Url.AbsolutePath];

String tempQuery = context.Request.Url.Query;

String url = String.Format("{0}?{1}", tempMap, tempQuery);

context.Server.Transfer(url);

}

doesn't work because it doesn't consider map of type UrlMap to be
instantiated...

Any help would be greatly appreciated
Cheers
Colin B
 
M

Magdelin

I don't know how you have done your controller mapping in
your web.config file. You will have to use absolute path
in the map. See the example:

Assuming "WebApp" to be your virtual directory, controller
mapping should be as follows:
<configuration>

<configSections>
<section name="commandSettings"
type="YourNamespace.UrlMap,WebApp" />
</configSections>

<system.web>

<httpHandlers>
<add verb="*" path="Command*.aspx"
type="YourNamespace.Handler, WebApp"/>
</httpHandlers>

</system.web>
<commandSettings>
<entries>
<entry key="/WebApp/Command1.aspx" url="RealPage1.aspx" />
<entry key="/WebApp/Command2.aspx" url="RealPage2.aspx" />
</entries>
</commandSettings>
</configuration>

where Command1.aspx and Command2.aspx may not be physical
files. The path you have used in the "key" attribute will
be used by the UrlMapper to resolve the path of the file
in "url" attribute.

Hope this might help.

Magdelin
 
C

Colin Basterfield

Hi,

Thanks for that I will check thro the way I set that up in web.config, and
come back with feedback.

Thanks again
Colin

Magdelin said:
I don't know how you have done your controller mapping in
your web.config file. You will have to use absolute path
in the map. See the example:

Assuming "WebApp" to be your virtual directory, controller
mapping should be as follows:
<configuration>

<configSections>
<section name="commandSettings"
type="YourNamespace.UrlMap,WebApp" />
</configSections>

<system.web>

<httpHandlers>
<add verb="*" path="Command*.aspx"
type="YourNamespace.Handler, WebApp"/>
</httpHandlers>

</system.web>
<commandSettings>
<entries>
<entry key="/WebApp/Command1.aspx" url="RealPage1.aspx" />
<entry key="/WebApp/Command2.aspx" url="RealPage2.aspx" />
</entries>
</commandSettings>
</configuration>

where Command1.aspx and Command2.aspx may not be physical
files. The path you have used in the "key" attribute will
be used by the UrlMapper to resolve the path of the file
in "url" attribute.

Hope this might help.

Magdelin
-----Original Message-----
Hi,

has anyone (tried to) implement the Front Controller pattern as described at

http://msdn.microsoft.com/architecture/patterns/ImpFrontCo ntrollerInASP/

I'm having trouble resolving the controller.mapping section in the
web.config file, as it is used in UrlMap.cs and that is used by
RedirectingCommand.cs in the samples given in the article above.

Does anyone know how this bit is meant to work? The code I have compiled
fails because

private UrlMap map = UrlMap.SoleInstance;

and then

public void Execute(HttpContext context)

{

OnExecute(context);

String tempMap = map.Map [context.Request.Url.AbsolutePath];

String tempQuery = context.Request.Url.Query;

String url = String.Format("{0}?{1}", tempMap, tempQuery);

context.Server.Transfer(url);

}

doesn't work because it doesn't consider map of type UrlMap to be
instantiated...

Any help would be greatly appreciated
Cheers
Colin B


.
 

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,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top