Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

My question is: Can I use my routing variables as a response. I.E. rather that redirecting to url can I redirect the response to an IHttpHandler instead?

I ask because I want to redirect users who perform site searches to a single results page in the "pass" subdomain ("http://pass.myweb.co.uk") and I want to know if there is a better way than specifying a URL.

Exposition to follow:

So I have a custom RouteHandler that manages all of my urls, pages and page queries. I have several subdomains, each with their own Page lists, each page may have a page list and / or a query handler list. This makes queries a lot easier to handle and is a great way to manage my pages.

At some point I would like to include these handlers in a db table or two. That way I can create a web interface to manage them, so I'm foreseeing a full CMS comming out of this one day.

Here are some examples:

SubDomain Handler Usage:
C#
//Here I have the Pass subdomain handler.
private static SubDomainHandler passSubDomainHandler()
{
    //SubDomainHandlers require a root.  Any other PageHandlers will be reached via a url
    return new SubDomainHandler("pass",
        
        //root is always called "root" but it doesn't matter
        getPassRootHub(),
        
        // This Page is called "ClaimRef" and has a QueryHandler
        getPassClaimRefPageHandler(),

        //This is my new page serving up search results based on a keyword and user roles
        getSearchResultsPageHandler()
        );
}


You may be keen to see what the classes SubDomainHandler, PageHandler & QueryHandler actually do, but trust me, it's dull as dish water.

C#
Search Results PageHandler:
        private static PageHandler<Pages.Search.SearchResults> getSearchResultsPageHandler()
        {
            //The Type is the aspx.cs class.  
            return new PageHandler<Pages.Search.SearchResults>( 
                   "SearchResults", //The text is how to find it from the URL
                   getSearchResultsQueryHandler());  //This specifies a query handler.  These are cool ^_^           
        }


As with the SubDomainHandler, a number of pages can be included in the constructor, each would be a URL after "SearchResults". We can also use QueryHandlers at this stage which do some cool stuff.

QueryHandler:
C#
private static QueryHandler<Pages.Search.SearchResults> getSearchResultsQueryHandler()
{
    //These include a page to handle the actual query.
    return new QueryHandler<Pages.Search.SearchResults>(
           @"[\d\w]+" //The text is what will appear on the end of the URL
    );
}



In this case I have a generic query handler. Any text after the SearchResults/ url will be the search text. If I have other URL routes after this URL I can instead use the text "Keyword_[\d\w]". This ensures that there is no ambiguity in the URL paths. If that was the case then the page would have a Page.RouteData.Values["Keyword"]. This is a generic query so there is a Page.RouteData.Values["Parameter"] by default.

My plan is to have wonderfully hackable URLS. My favorite query handler handles dates so the URL "web.co.uk/Data/2015/05/16" returns the full date range in the RouteData, even if you miss off the day or the day and the month!
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900