Objective:
Recent friends who use urlrewriting sometimes encounter asp.net Ajax and AJAX Control Toolkit controls that are not working properly, and are tricky for developers with no relevant experience. This article discusses some of the compatibility issues that should be noted when using ASP.net AJAX and urlrewriting through case studies and relative solutions.
Problem Recurrence:
A simple urlrewriting application is a path redirection from client to resource request, which is typically written like the following code 1 and code 2:
Code 1:
// If the requested file exists
if (File.Exists(Request.PhysicalPath))
{
// Do nothing here, just serve the file
}
// If the file does not exist then
else if (!File.Exists(Request.PhysicalPath))
{
// Get the URL requested by the user
string sRequestedURL = Request.Path.Replace(".aspx", "").Replace ("/gratis24/","");
// You can retrieve the ID of the content from database that is
// relevant to this requested URL (as per your business logic)
string sId;
sId = GetContentIDByPath(sRequestedURL);
// The ShowContents.aspx page should show contents relevant to
// the ID that is passed here
string sTargetURL = "~/Kategori.aspx?category=" + sId;
// Owing to RewritePath, the user will see requested URL in the
// address bar
// The second argument should be false, to keep your references
// to images, css files
Context.RewritePath(sTargetURL, false);
Code 2:
//in global.asax
void Application_BeginRequest(object sender, EventArgs e)
{
System.Web.HttpContext httpContext = HttpContext.Current;
String currentURL = httpContext.Request.Path.ToLower();
//Creates the physical path on the server
string physicalPath = httpContext.Server.MapPath(currentURL.Substring (currentURL.LastIndexOf("/") + 1));
//checks to see if the file does not exsists.
if (!System.IO.File.Exists(physicalPath) && !currentURL.EndsWith ("webresource.axd"))
{
string reWritePage = "ViewProfile.aspx";
httpContext.RewritePath(reWritePage);
}
}
However, when we use the above code for urlrewriting and use ASP.net ajax or AJAX Control Toolkit in the page, we get the ' sys ' is undefined error warning, and the AJAX controls are not working properly, Totally not work.