Absolute Url in routes and HtmlHelper.ActionLink

Last post 04-22-2008 11:04 AM by jdcrutchley. 4 replies.

Sort Posts:

  • Absolute Url in routes and HtmlHelper.ActionLink

    12-15-2007, 1:27 PM
    • Loading...
    • jpak
    • Joined on 12-15-2007, 5:32 PM
    • Posts 2

    I was wondering if there will be support for absolute Urls in HtmlHelper.ActionLink like in Monorail, in particular to generate https links for a login page for example.
    In Monorail, you can pass Absolute/Relative and the protocol in the dictionary parameter.

    Also on the routes, how would we handle a case like in Subtext:
    A community site is mapped to a main domain, but each account can optionally have its own domain and aliases so that for example:

    maindomain/accountidentifier/blog maps to BlogController, default action passing accountidentifier
    accountdomain/blog maps to the same controller and action passing accountdomain

    The controller is then responsible to pull the right account from the DB using either accountidentifier or accountdomain.

    It would be nice if one did not have to go through as much effort as in Subtext to handle this in an application.

     

     

  • Re: Absolute Url in routes and HtmlHelper.ActionLink

    12-15-2007, 2:46 PM
    • Loading...
    • slynch
    • Joined on 09-03-2002, 4:18 PM
    • Michigan
    • Posts 71

    Not really sure about the first one, but I suspect that at the moment, if you wanted to get it to work right now you would have to subclass the RouteTable, RouteCollection and probobly the Route classes to have them take into account the domain. Which wouldnt be to hard, but I'm sure this is something they will be adding in a future drop.

    The second question is alot easier, as long as you exclude the aggregate page for now, to get to work with this CTP, though would likely change if they implimented the first one.

    For a blog I would use routes like these.

    RouteTable.Routes.Add(new Route
    {
    	Url = "Admin/[action]",
    	Defaults = new { controller = "Admin", action="Index", account=""},
    	RouteHandler = typeof(MvcRouteHandler)
    });
    RouteTable.Routes.Add(new Route
    {
    	Url = "Archive/[action]",
    	Defaults = new { controller = "Archive", action="Index", account=""},
    	RouteHandler = typeof(MvcRouteHandler)
    });
    RouteTable.Routes.Add(new Route
    {
    	Url = "[account]/[controller]/[action]",
    	Defaults = new { action = "Index" },
    	RouteHandler = typeof(MvcRouteHandler)
    });
     

    Then in the different controllers, if Account comes in empty, have it look at the HttpRequest for the domain name and use that to lookup the account. The only part I'm not quite sure how fits in is doing the appropriate redirects to the blog's main url, since I would not want the aliases to do anything but a redirect to the main url, though personally I would probobly just do a Response.Redirect to the main url.

    Sean Lynch - Blog
  • Re: Absolute Url in routes and HtmlHelper.ActionLink

    12-15-2007, 3:15 PM
    • Loading...
    • abombss
    • Joined on 06-27-2006, 4:13 PM
    • Chicago, IL
    • Posts 164

    Routing right now is the least extensible piece of the framework and needs the most improvement, imho.

    RouteCollection way too heavy and is not extendable at all and this causes problems when you create handlers for custom routing, then those custom "rules" you perform in the handler can never be used for bidirectional routing.  The easy thing to do would be to split out the functionality of RouteCollection into a composition of two services.  IRouteResolver and IUrlResolver or something like that.  This way if we wanted to send a parameter SubDomain as part of the properties our own custom IUrlResolver could handle that case and generate the appropriate url.  Or we could send Secured=True or Port=8080 or whatever and we could handle all those cases ourselves.

    I don't think it would be wise for MS to just make a bunch special parameters, like they did with HttpMethod, to try and cover all the use cases.

    There also needs to be major work done on performance in the RouteCollection, its just way too heavy right now and does unnecessary locking.  If you reflect over the code you will see that every time you call GetRouteData or GetUrl it locks the routes.  What does this mean, it means every request locks the routes and every link render locks routes.  You will have contention between rendering and routing which is absurd considering every request has to go through the RouteCollection and sit and wait for a lock just to move on.

    They should at least use ReaderLock and WriterLock but personally why lock?  What are the odds I dynamically add routes using multiple threads in my app? Slim to none.  And if I do what is the window of time that something could be screwed up, small.  If I want to do this let me worry about my own concurrency don't force it on me.  Most routes are going to be initialized in the Application_OnStart which is only called once correct?

    Incosistencies with case sensitivity are also an issue.  Everywhere I look things are case insensitive, why are validation rules case sensitive regular expressions?  Why are validation rules not aggregated and compiled?  If I have an application with a validator on id and 100 routes because I have areas and I am nesting controllers, why are we not compiling that same id validator to a single regex?  Why do I need write validators like @"[eE][dD][iI][tT]|[dD][eE][lL][eE][tT][eE]" instead of just @"edit|delete"?

    I look forward to hearing about what improvements MS has for Routing in the next CTP.  I already like the fact they will allow Dictionaries for parameters instead of just anonymous types, lets see what else they can do?

    Just my .02, I should have another blog post up about routing and its need for improvement shortly.

    Adam Tybor -- abombss.com
     

    Adam Tybor -- abombss.com
    Filed under: ,
  • Re: Absolute Url in routes and HtmlHelper.ActionLink

    12-15-2007, 11:00 PM
    • Loading...
    • robconery
    • Joined on 02-23-2005, 10:16 PM
    • Posts 161
    • AspNetTeam

    jpak:
    I was wondering if there will be support for absolute Urls in HtmlHelper.ActionLink like in Monorail, in particular to generate https links for a login page for example.
    In Monorail, you can pass Absolute/Relative and the protocol in the dictionary parameter.
     

    Great idea - I'll work this for the next drop. 

  • Re: Absolute Url in routes and HtmlHelper.ActionLink

    04-22-2008, 11:04 AM

    Did this ever get in?  I don't see it in the latest stuff.

    -- jdc
Page 1 of 1 (5 items)