Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesCustom URL Routing issue with DNNCustom URL Routing issue with DNN
Previous
 
Next
New Post
11/9/2013 4:40 AM
 

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

 
New Post
11/9/2013 12:11 PM
 

Hi,

First of all if you urls are  mydomain.com/MyPage.aspx?cat=myCat&prod=myProd it meen you dont use the rigth way to generate urls in dnn.

You have to use Globals.NavigateUrl(...) for generating urls (or EditUrl).

Ones you have done this, you have to create a url rewriter provider for your module to extend the url rewriter with your rules.

For DNN 7.1.x you can find more info : 

http://www.dnnsoftware.com/wiki/page/...

An alternative is to use OpenUrlRewriter 

https://openurlrewriter.codeplex.com

and here info to create your custom provider for your module

https://openurlrewriter.codeplex.com/... 

(Little bit easyer to implement, i think.)

Regards,

 
New Post
11/11/2013 12:19 AM
 

Thanks Sacha,

I knew there was something specific with DNN when it came to routing. I shall follow your recommendations and see if it works. I shall update once I'm through.

 -Asif

 
Previous
 
Next
HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesCustom URL Routing issue with DNNCustom URL Routing issue with DNN


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out