Creating a DomainRoute route - Virtual path

Last post 11-05-2009 1:53 AM by maartenba. 2 replies.

Sort Posts:

  • Hmm [^o)] Creating a DomainRoute route - Virtual path

    04-15-2009, 8:50 AM
    • Member
      368 point Member
    • maartenba
    • Member since 01-23-2008, 8:27 AM
    • Belgium
    • Posts 76

    I'm currently working on a DomainRoute class, which would enable routing based on (sub)domains, so for example http://products.example.com maps to the ProductsController.

    So far so good, route parsing and stuff like that is no problem. However, I'm hitting a wall here. Let's have a look at this code snippet:

    1        public class DomainRoute : RouteBase
    2        {
    3            // ...
    4    
    5            public override VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary values)
    6            {
    7                // ...
    8                // Some logic happens here, and url is generated
    9                // into someting like "http://account.example.com/Register"
    10               // ...
    11   
    12               return new VirtualPathData(this, url);
    13           }
    14       }
    
     

    This GetVirtualPath method returns a virtual path (in a VirtualPathData instance) based on the request context and the route dictionary values, which is then used by for example the HtmlHelpers.ActionLink() method. Now say we have some logic that generates a URL like "http://account.example.com/Register". Problem here is that this URL is treated as a virtual path, meaning that the URL rendered to my view is something like "http://localhost/http:/account.example.com/Register".

    Question: does anyone have an idea on how to trick ASP.NET MVC and the routing infrastructure into treating my URL as a full URL instead of a virtual path?

    Visit my blog at http://blog.maartenballiauw.be

    Order my book ASP.NET MVC 1.0 Quickly via http://www.packtpub.com/asp-net-model-view-controller-1-0-quickly/book
  • Re: Creating a DomainRoute route - Virtual path

    11-04-2009, 9:18 PM
    • Member
      4 point Member
    • Orik007
    • Member since 01-16-2007, 8:54 AM
    • Posts 6

    This is very good question, indeed. Any progress?
    Thx 

  • Re: Creating a DomainRoute route - Virtual path

    11-05-2009, 1:53 AM
    • Member
      368 point Member
    • maartenba
    • Member since 01-23-2008, 8:27 AM
    • Belgium
    • Posts 76
    Visit my blog at http://blog.maartenballiauw.be

    Order my book ASP.NET MVC 1.0 Quickly via http://www.packtpub.com/asp-net-model-view-controller-1-0-quickly/book
Page 1 of 1 (3 items)