Professional web hosting - CHAPTER 5 PERMUTATIONS PATTERN 129 public interface

CHAPTER 5 PERMUTATIONS PATTERN 129 public interface IURLRewriter bool IsResource(HttpRequest request) void WriteRedirection( HttpRequest request) public interface IRewriter bool WriteRedirection(string mimetype) The interface IURLRewriter is the URL rewriter component and has two methods: IsResource and WriteRedirection. The method IsResource is used to recognize a resource URL, such as http://mydomain.com/account/joesmith. The method WriteRedirection is used to rewrite the URL. Even though it is not obvious, the IRewriter component is wired to the internals of the IURLRewriter component. The interface IRewriter also has a single method, WriteRedirection, that is used to rewrite the URL. The interface IRewriter is responsible for converting the resource into an appropriate representation. Relating the interface IRewriter to Figure 5-9, it would mean converting the URL /bankaccount/login to the URL /bankaccount/login.jsp. The way that the URL is rewritten is not based on the URL itself but on the MIME type. However, an IRewriterand IURLRewriter implementation could be coded to rewrite the URL based on multiple HTTP headers. When rewriting a URL by using multiple HTTP headers, a priority ordering is used (for example, Accept before Accept-Language). Getting back to the IRewriter interface, if the URL is rewritten, then the WriteRedirection method returns true; otherwise, a false is returned. As will shortly be illustrated, the URLRewriterASPNet class implements the IURLRewriter E B V N interface, and DefaultRewriter implements the IRewriter interface. Based on the implementation types, the interface instances of IRewriter and IURLRewriter are wired together in the OnBeginRequest filter phase of an ASP.NET application. The following source code illustrates the implementation of OnBeginRequest in the global.asax file: void Application_OnBeginRequest(Object sender, EventArgs e) HttpApplication app = (HttpApplication)sender; IRewriter rewriter = new DefaultRewriter( app) IURLRewriter router = new URLRewriterASPNet( rewriter) if (router.IsResource(app.Request)) router.WriteRedirection(app.Request) The OnBeginRequest function is named and defined based on the requirements of ASP.NET. When implementing anyof the filter phases in ASP.NET, they are propagated as .NET events;there fore, the signature of the method is fixed to the first parameter being an Objectinstance, and the second parameter being an EventArgs instance. Sender is an instance of HttpApplication, which represents the ASP.NET application. Looking closer at the instantiation of URLRewriterASPNET, you can see that it is wired to an IRewriterinstance by using the URLRewriterASPNet constructor. After the instantiations, the first if statement uses the method IsResource to test whether the HTTP request is a resource. If the HTTP request is a resource, the method WriteRedirection is called to rewrite the URL.
Check Tomcat Web Hosting services for best quality webspace to host your web application.

Leave a Reply