Question

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!

Was it helpful?

Solution

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.

OTHER TIPS

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.

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"/>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top