views:

752

answers:

4

I'm trying to setup some friendly URLs on a SharePoint website. I know that I can do the ASP.Net 2.0 friendly URLs using RewritePath, but I was wondering if it was possible to make use of the System.Web.Routing that comes with ASP.NET 3.5 SP1.

I think I've figured out how to get my route table loaded, but I'm not clear on what method to use to get the correct IHttpHandler to pass out.

Thanks!

A: 

Hi Bryant,

It should be as easy as the below.

var route = new Route("blah/{*path}", new MyRouteHandler());
RouteTable.Routes.Add(route);

public class MyRouteHandler : IRouteHandler
{
    public IHttpHandler GetHttpHandler(RequestContext requestContext)
    {
        // return some HTTP handler here
    }
}

Then register System.Web.Routing.UrlRoutingModule under HTTP modules in web.config and you should be good to go.

<add name="Routing" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
Hey Ryan, nice to see you. That is the easy part. The hard part is figuing out what Http Handler to return.
Bryant
Did anyone ever find a way to return a HTTPHandler that will work with SharePoint?
Daniel Pollard
+1  A: 

I've been asked to look at this as part of an Share Point evaluation process.

My understanding is that the uri template is essentially host name followed by the recursive folder structure.

This is further complicated by Share Point truncating the uri at 255 characters. So if you have a particularly deep or verbose folder structure then your uri can become invalid.

I was thinking about essentially prettifying / tidying up the uri by follow a human readable convention and convert to the Share Point convention. i.e:

http://myhostname.com/docs/human-resources/case-files/2009/reviews/ed-blackburn.docx

converts to Share Points:

http://myhostname.com/human%20resources/case%20files/2009/reviews/ed%20blackburn.docx

Any additional required services can be controlled by the controller.

If longer than 255 characters some kind of tinyurl approach would be my initial suggestion.

Ed Blackburn
A: 

I ended up taking what Ryan had:

var route = new Route("blah/{*path}", new MyRouteHandler());
RouteTable.Routes.Add(route);
public class MyRouteHandler : IRouteHandler
{    
public IHttpHandler GetHttpHandler(RequestContext requestContext)    
{        
     //rewrite to some know sharepoint path
     HttpContext.Current.RewritePath("~/Pages/Default.aspx");

     // return some HTTP handler here  
     return new DefaultHttpHandler();  

}}

That seems to work ok for me.

Daniel Pollard
@Daniel: have you run that past the SharePoint developers yet? With new versions of .NET and of SharePoint coming up, I'd want to make sure this code was going to continue to "seem to work" in the near future. Maybe ask on one of the MSDN SharePoint forums?
John Saunders