Hi,
We are developing a custom module for DNN 7 which generate some URLs
eg: mydomain.com/MyPage.aspx?cat=myCat&prod=myProd
where MyPage.aspx page is a page created on DNN which contains our working module and when the above URL is called it works fine.
We now wanted to make this SEO friendly and wanted to write our custom logic and URL routing.
eg: mydomain.com/MyPage/myCat/myProd to route to the above page.
We added the following lines in the web.config page:
Code:
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<remove name="UrlRoutingModule"/>
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</modules>
<handlers>
<add name="UrlRoutingHandler" preCondition="integratedMode" verb="*" path="UrlRouting.axd" type="System.Web.HttpForbiddenHandler, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
</handlers>
</system.webServer>
and the following code in Global.asax file:
<%@ Application Inherits="DotNetNuke.Web.Common.Internal.DotNetNukeHttpApplication" Language="C#" %>
<%@ Import Namespace="System.Web.Routing" %>
<%@ Import Namespace="System.Web.Compilation" %>
<script runat="server">
public class myPageCategoryRouteHandler : IRouteHandler
{
public IHttpHandler GetHttpHandler(RequestContext requestContext)
{
string categoryName = requestContext.RouteData.Values["Category"] as string;
string productName = requestContext.RouteData.Values["Product"] as string;
if (string.IsNullOrEmpty(categoryName))
{
HttpContext.Current.Items["Category"] = "defaultCategory";
return BuildManager.CreateInstanceFromVirtualPath("/myPage.aspx", typeof(Page)) as Page;
}
else
{
HttpContext.Current.Items["Category"] = categoryName;
if (!String.IsNullOrEmpty(productName))
{
HttpContext.Current.Items["Product"] = productName;
return BuildManager.CreateInstanceFromVirtualPath("/myPage.aspx", typeof(Page)) as Page;
}
return BuildManager.CreateInstanceFromVirtualPath("/myPage.aspx", typeof(Page)) as Page;
}
}
}
void Application_Start(object sender, EventArgs e)
{
RegisterRoutes(RouteTable.Routes);
}
void RegisterRoutes(RouteCollection routes)
{
routes.Add("Credit Cards Products",new Route("myPage/{Category}/{Product}", new myPageCategoryRouteHandler()));
routes.Add("Credit Cards",new Route("myPage/{Category}", new myPageCategoryRouteHandler()));
}
void Application_End(object sender, EventArgs e)
{
// Code that runs on application shutdown
}
void Application_Error(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs
}
void Session_Start(object sender, EventArgs e)
{
// Code that runs when a new session is started
}
void Session_End(object sender, EventArgs e)
{
// Code that runs when a session ends.
// Note: The Session_End event is raised only when the sessionstate mode
// is set to InProc in the Web.config file. If session mode is set to StateServer
// or SQLServer, the event is not raised.
}
</script>
But Whatever we do we get a 404 file not found error.
it cannot be the hosting server because I created a blank site on the server with a test domain and set the similar URL routing with the global.asax and web.config, basically a simple asp.net website, and the URL routing worked flawlessly. so I figured the problem has to be with DNN.
Can anyone point out what we are doing wrong? Do we have to do routing in a different way in DNN? any help would be really great.
Thanks,
Asif