Url Routing in ASP.NET 3.5 breaks AJAX

G

gerry

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 );
 
D

Dmitri Vaganov

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;
}
}
 
D

Dmitri Vaganov

Gerry, I added a custom constraint class to catch the pages with "." in the
name. That fixed the issue. Thanks for all your help!!!
 

Ask a Question

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. After that, you can post your question and our members will help you out.

Ask a Question

Top