Trying to Url Routing in .NET 4.0, VS2010, IIS7

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
13 年 前
I am trying to use the Url Routing features of .NET 3.5/4.0 with "vanilla" web forms in the main directory of nopCommerce (pages located with Default.aspx, Account.aspx, etc.

In order for this to work, I need to register the routes in the global.asax using the following code (for example):


    void Application_Start(object sender, EventArgs e)
    {
        RegisterRoutes(RouteTable.Routes);
    }
    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.MapPageRoute("View_Continent", "Continent/{ContinentName}", "~/Account.aspx");
    }

When performing the above code, the "routes.MapPageRoute" command must contain a final parm (the specific real page to route the user to) that begins with "~"/, otherwise an error is thrown during execution.

The code in the code-behind file that is building an outbound Url (for example) uses code such as:

            string sUrl = "";
            string sCont = "";
            sCont = "continentname";
            RouteValueDictionary parameters = null;
            parameters = new RouteValueDictionary(new { ContinentName = sCont });
            VirtualPathData vpd = null;
            vpd = RouteTable.Routes.GetVirtualPath(null, "View_Continent", parameters);
            sUrl = vpd.VirtualPath;
            HyperLink2.NavigateUrl = sUrl;

When this "code-behind" code executes, it creates a desired "friendly" Url such as http://localhost:11139/Continent/continentname.  However, when this Url is clicked on the screen, the user is directed to http://localhost:11139/Continent/continentname/default.aspx, not http://localhost:11139/nopCommerce/Account.aspx (based on the route added via the code shown before this).

Does anyone know how to use this Url Routing with nopCommerce and how to structure the Url encoding to achieve the correct result?

Thanks in advance!

Lynn
13 年 前
I have (since submitting this item) discovered

http://blogs.planetcloud.co.uk/mygreatdiscovery/post/Using-routing-in-a-web-forms-application-(nopCommerce).aspx

as a means of learning how to accomplish this change.  After reading this blog entry of Ben's several times this evening (thank you, Ben) I am still confused over a couple of points.

(1) In the Administration area of nopCommerce, there is a checkbox for turning off URL rewriting.  I have done that, yet no matter what I do I cannot seem to get a URL route to store properly or to execute properly.  This could be because URL rewriting and URL routing cannot co-exist.  I'm afraid I am not knowledgeable enough to know the answer to this question.

(2) We are going to use nopCommerce for the purpose it was intended for, but do NOT have need for URL rewriting or routing for Categories, Products, or Manufacturers.  We do, however, have need for URL routing for other data that we are adding to our system.  If we remove (or comment out) the UrlRewriteModule declarations in web.config AND turn off URL rewriting in the Administrative section, will we be able to add routing FOR OUR ITEMS ONLY?  If we do not need rewriting for the standard nopCommerce items, then I would think this would work.  Has anyone tried this?  If so, will this approach work?

Thanks!

Lynn
13 年 前
Lynn,

1) What's the advantage of URL Routing over the existing URL Rewriting? Is it faster?
2) If so, I'm looking forward to someone implementing this in nopCommerce. Please provide your code.

Currently, I am almost finished with some SEO enhancements that will make nopCommerce a much better e-commerce solution. For example, url rewriting image paths to seo friendly paths, seo image alt texts, seo link titles, and renaming pages to exclude the id from the url). I can't believe or even begin to phathom the reason for including the id in the page name. It doesn't make a bit of sense. From an SEO standpoint, it doesn't make sense because search engines don't know how to correlate numbers with content. I believe in the future nopCommerce will be excellent for e-commerce. However, if the switch to MVC causes problems, then I'm abondoning nop and starting my own open source solution.

V/R, Bruce
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.