By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,708 Members | 2,086 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,708 IT Pros & Developers. It's quick & easy.

Front Controller testing

P: n/a
Hi All.
I have been trying to implement this front controller On MS site and
finally i have no error on the pages but i dont its working or not.
When i execute the pages from Browser i dont get no result. I have hard
coded the Database getting site name part still no luck.
I have try to write the context that i am passing, seems empty.
If someone pls help me out with testing this i would appriciate it.
May be someone can post the working code here. or tell me what am i
doing wrong
This is how i call it
http://localhost/XFrontController/actualpage1.aspx

actualpage1.aspx
public class actualpage1.aspx : BasePage
{
protected System.Web.UI.WebControls.Label pageNumber;

protected override void PageLoadEvent(object sender, System.EventArgs
e)
{
pageNumber.Text = "Overloaded 1";
}

}
BasePage.cs
protected Label eMail;
protected Label siteName;
virtual protected void PageLoadEvent(object sender, System.EventArgs e)
{}
protected void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
eMail.Text = (string)Context.Items["address"];
siteName.Text = (string)Context.Items["site"];
PageLoadEvent(sender, e);
}
}

Handler.cs
public class Handler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
Command command = CommandFactory.Make(context.Request.Params);
command.Execute(context); }
public bool IsReusable
{get { return true;} }
}
Command.cs, same execute interface
CommandFactory.Cs
public class CommandFactory
{
public static Command Make(NameValueCollection parms)
{
string siteName = parms["site"];

Command command = new UnknownCommand();
if(siteName == null || siteName.Equals("micro"))
command = new MicroSite();
else if(siteName.Equals("macro"))
command = new MacroSite();
return command;
}
}

,redirectCommand.cs
these class are same as MS site.

WebConfig

<configSections>
<section name="commandSettings" type="UrlMap,XFrontController" />
</configSections>

<commandSettings>
<entries>
<entry key="/XFrontController/ActualPage1.aspx"
url="ActualPage1.aspx" />
<entry key="/XFrontController/ActualPage2.aspx"
url="ActualPage2.aspx" />
</entries>
</commandSettings>

<system.web>

<httpHandlers>
<add verb="*" path="Page*.aspx" type="Handler,IAFrontController" />
</httpHandlers>

MacroSite and MicroSite.cs i have hardCode the call

public class MacroSite : RedirectingCommand
{
protected override void OnExecute(HttpContext context)
{
string name = context.User.Identity.Name;

context.Items["address"] =
"macro";//MacroUsersDatabase.RetrieveAddress(name);
context.Items["site"] = "Macro-Site";
}
}

public class MicroSite : RedirectingCommand
{
protected override void OnExecute(HttpContext context)
{
string name = context.User.Identity.Name;

context.Items["address"] = "micro"; //
WebUsersDatabase.RetrieveAddress(name);
context.Items["site"] = "Micro-Site";
}
}

I did not change
RedirectingCommand,UrlMap,
public class UnknownCommand : RedirectingCommand
{
protected override void OnExecute(HttpContext context)
{
string name = context.User.Identity.Name;
context.Items["address"] = "user " + name + " is unknown";
context.Items["site"] = "Unknown";
}

}

Nov 19 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.