jeudi 21 avril 2016

Creating Cutom RouteBase class

I want to know what is the function of httpContext.Request.AppRelativeCurrentExecutionFilePath in below code. Please, explain how the routing system matches the requested url:

public override RouteData GetRouteData(HttpContextBase httpContext) 
{ 
RouteData result = null; 
string requestedURL = string.Empty; 
for (int i = 0; i < urls.Length; i++) 
{                   
 if(httpContext.Request.AppRelativeCurrentExecutionFilePath.Contains(urls[i])) 
 { 
    requestedURL = httpContext.Request.AppRelativeCurrentExecutionFilePath; 
    break; 
 } 
}     

if (!string.IsNullOrEmpty(requestedURL)) 
{ 
   result = new RouteData(this, new MvcRouteHandler()); 
   result.Values.Add("controller", "CustomRoute"); 
   result.Values.Add("action", "DirectCustomUrls"); 
   result.Values.Add("customUrl", requestedURL); 
} 
   return result; 
}

Aucun commentaire:

Enregistrer un commentaire