Url Routing in ASP.NET 3.5 breaks AJAX

Discussion in 'Microsoft Dot NET Framework' started by Dmitri Vaganov, May 28, 2010.

  1. Dmitri Vaganov, May 28, 2010
    #1
    1. Advertisements

  2. Dmitri Vaganov

    gerry Guest

    this happens when you have wildcarding in place
    one way to solve this to add a constraint to your routes so they only work
    for .aspx , ... files - something like this :

    RouteValueDictionary constraints = new RouteValueDictionary( new { Page =
    @".*\.aspx*$" } );
    Route rt = new Route( "{Page}" , RouteHandler );
    rt.Constraints = constraints;
    routes.Add( "RouteHandler" , rt );


    "Dmitri Vaganov" <> wrote in message
    news:...
    > Hello I created custom URL routing in ASP.NET 3.5
    > (http://blogs.msdn.com/b/mikeormond/archive/2008/05/14/using-asp-net-routing-independent-of-mvc.aspx),
    > but my AJAX code is giving me error now: 'Sys' is undefined. When I remove
    > the routing, AJAX works fine. I am using standard Microsoft AJAX
    > libraries.
    > Please help!
    >
     
    gerry, May 28, 2010
    #2
    1. Advertisements

  3. Thanks for your help, Gerry. When I add the constraint, the Routing stops
    redirecting to the page that I specified. When I remove constraint it works
    fine.

    Here is my routing code:

    RouteValueDictionary constraints = new RouteValueDictionary(new
    {
    Page =
    @".*\.aspx*$"
    });
    Route rt = new Route("{Page}", new
    CustomRouteHandler("~/WelcomePage.aspx"));
    rt.Constraints = constraints;
    routes.Add("RouteHandler", rt);

    Here is CustomRouteHandler:

    public class CustomRouteHandler : IRouteHandler
    {
    public CustomRouteHandler(string virtualPath)
    {
    this.VirtualPath = virtualPath;
    }

    public string VirtualPath { get; private set; }

    public IHttpHandler GetHttpHandler(RequestContext
    requestContext)
    {
    foreach (var urlParm in requestContext.RouteData.Values)
    {
    requestContext.HttpContext.Items[urlParm.Key] = urlParm.Value;
    }
    var page = BuildManager.CreateInstanceFromVirtualPath
    (VirtualPath, typeof(Page)) as IHttpHandler;

    return page;
    }
    }

    "gerry" wrote:

    > this happens when you have wildcarding in place
    > one way to solve this to add a constraint to your routes so they only work
    > for .aspx , ... files - something like this :
    >
    > RouteValueDictionary constraints = new RouteValueDictionary( new { Page =
    > @".*\.aspx*$" } );
    > Route rt = new Route( "{Page}" , RouteHandler );
    > rt.Constraints = constraints;
    > routes.Add( "RouteHandler" , rt );
    >
    >
    > "Dmitri Vaganov" <> wrote in message
    > news:...
    > > Hello I created custom URL routing in ASP.NET 3.5
    > > (http://blogs.msdn.com/b/mikeormond/archive/2008/05/14/using-asp-net-routing-independent-of-mvc.aspx),
    > > but my AJAX code is giving me error now: 'Sys' is undefined. When I remove
    > > the routing, AJAX works fine. I am using standard Microsoft AJAX
    > > libraries.
    > > Please help!
    > >

    >
    >
    > .
    >
     
    Dmitri Vaganov, Jun 1, 2010
    #3
  4. Gerry, I added a custom constraint class to catch the pages with "." in the
    name. That fixed the issue. Thanks for all your help!!!

    "gerry" wrote:

    > this happens when you have wildcarding in place
    > one way to solve this to add a constraint to your routes so they only work
    > for .aspx , ... files - something like this :
    >
    > RouteValueDictionary constraints = new RouteValueDictionary( new { Page =
    > @".*\.aspx*$" } );
    > Route rt = new Route( "{Page}" , RouteHandler );
    > rt.Constraints = constraints;
    > routes.Add( "RouteHandler" , rt );
    >
    >
    > "Dmitri Vaganov" <> wrote in message
    > news:...
    > > Hello I created custom URL routing in ASP.NET 3.5
    > > (http://blogs.msdn.com/b/mikeormond/archive/2008/05/14/using-asp-net-routing-independent-of-mvc.aspx),
    > > but my AJAX code is giving me error now: 'Sys' is undefined. When I remove
    > > the routing, AJAX works fine. I am using standard Microsoft AJAX
    > > libraries.
    > > Please help!
    > >

    >
    >
    > .
    >
     
    Dmitri Vaganov, Jun 1, 2010
    #4
    1. Advertisements

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Similar Threads
  1. Sasha Shevelev

    asp.net causing line breaks in javascript

    Sasha Shevelev, Aug 1, 2003, in forum: Microsoft Dot NET Framework
    Replies:
    1
    Views:
    957
    mburr
    Aug 1, 2003
  2. Hasani
    Replies:
    4
    Views:
    413
    Gary van der Merwe
    Oct 20, 2003
  3. David Hodges

    ASP.Net breaks after Framework 1.0 SP3

    David Hodges, Sep 14, 2004, in forum: Microsoft Dot NET Framework
    Replies:
    3
    Views:
    359
    Bert Hyman
    Sep 15, 2004
  4. Guest
    Replies:
    2
    Views:
    567
    Guest
    Apr 7, 2005
  5. Guest

    Not able to run ASP.Net applications-Error in ASP.Net

    Guest, Apr 11, 2005, in forum: Microsoft Dot NET Framework
    Replies:
    5
    Views:
    470
    Guest
    Apr 12, 2005
  6. Noulouk

    Check if mms:// or rtsp:// url exists (url not broken)

    Noulouk, Aug 11, 2005, in forum: Microsoft Dot NET Framework
    Replies:
    0
    Views:
    1,460
    Noulouk
    Aug 11, 2005
  7. mianiro

    ASP.NET/AJAX Accordion

    mianiro, Aug 16, 2007, in forum: Microsoft Dot NET Framework
    Replies:
    0
    Views:
    386
    mianiro
    Aug 16, 2007
  8. Mukesh

    AJAX AND url rewriting

    Mukesh, Sep 7, 2007, in forum: Microsoft Dot NET Framework
    Replies:
    6
    Views:
    583
    Mukesh
    Sep 14, 2007
Loading...