Using Url Routing in 1.90

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
13 years ago
After reading the blog entry by Ben Foster which is referenced in other items in this forum

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

I have attempted to implement these changes.  The first steps I have attempted to go through are:

(1) The turning off of the UrlRewriting functionality by commenting out all entries related to it in the web.config file.
(2) Turning on Url Routing using code from another web site where Url Routing is presently working properly.
(3) Adding additional items to the "RegisterRoutes" procedure code to ignore .axd's and favicon's using the code from Ben Foster's blog entry regarding these two items.

Please bear in mind that Url Routing is working just fine on this same VS2010/Windows7 Ultimte/64bit machine in another web site and that code was simply moved across for initial testing purposes.

The results of this work and testing are:

(1) In procedural code on .aspx pages, the RouteTable.Routes.GetVirtualPath(...) commands appear to be working as expected and desired.  The Url's created from these commands are correct and match those in the other web site where the Url Routing code came from.

(2) It would appear that none of the Url Routing is working going back into the server.  In other words, if there is a
"NavigateUrl" link on one of the site pages (such as Default.aspx) and I click on that link, I am redirected to Login.aspx (of course, I am already logged in at this point).  If I completel another login, I am redirected back to the Login.aspx page again.  This loop will continue infinitely regardless of how many times I log in.  None of the login logic was changed during these mod's at all.

It would appear that the introduction of the Url Routing table code into the global.asax file has, in some way, affected the ability of nopCommerce to know what is going on.

It should be noted that this testing was done multiple times with both possible settings for the "Enable Url Rewriting" checkbox in the Administrative section of the system.  This checkbox appears to not have any effect on the process.

If anyone knows where the "hook" is, or the code that still needs modification is, or has some ideas of how to resolve this strange behavior, please give me a shout.  I'm guessing that the Url Routing is not being executed on message input and that the system is "defaulting" to the login page because it doesn't know where else to send the user, but I have no idea where to look.

Thanks in advance!

Lynn
13 years ago
Can you post details of the link you are clicking and where you expect it to go, along with your routes.

I had to add some additional settings to web.config for IIS7. Below is the diff:


Added changes required for routing in IIS7

=== (+3,-2) nopCommerce 1.80/NopCommerceStore/web.config ===
@@ -27,6 +27,7 @@
      </expressionBuilders>
      <assemblies>
        <add assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
+        <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
       </assemblies>
     </compilation>
    <authentication mode="Forms">
@@ -117,7 +118,7 @@
  </system.web>
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
-    <modules>
+    <modules runAllManagedModulesForAllRequests="true">
      <remove name="NopCommerceFilter"/>
      <!--<remove name="UrlRewriteModule"/>-->
      <add name="MembershipHttpModule" preCondition="managedHandler" type="NopSolutions.NopCommerce.HttpModules.MembershipHttpModule, Nop.HttpModules.MembershipModule"/>


You may also need to map a default route for the home page:


routes.MapPageRoute("", "", "~/default.aspx");


Hope this helps
13 years ago
I also try to implement Ben's changes but I did not have any luck at all.

I have few problems.

// for this part of code it tell me it .toSlug(int.maxValue) does not exist

public static string ToSlug(this string source) {
    return source.ToSlug(int.MaxValue);
}

// Validator object does not exist and also productName.ToSlug(100)
public static string GenerateProductSlug(string productName, int productId){
    return Validator.ValidateSlug(productName.ToSlug(100), productId, ProductManager.GetProductSlugs());
}

// Cache.Get does not except three arguments
public static IDictionary<int, string> GetProductSlugs() {
    return Cache.Get(product_slugs_key, 30, ()=> {
        var db = ObjectContextHelper.CurrentObjectContext;
        return (from p in db.Products
                select new {
                    Id = p.ProductId,
                    Slug = p.Slug
                }).ToDictionary(x => x.Id, x => x.Slug);
    });          
}

13 years ago
Has anyone been able to use routing with 1.9? The only thing I have not been able to figure out is why I lose the session  / context on routed URL's. I found a bit of information on various websites and forums but none of the approaches they discuss have worked.

Does anyone have an idea for me to try?
13 years ago
Follow Up, It would seem if I add .aspx to the rewritten url the session state restores itself. See example below.

HttpContext.Current.Session is equal to null in the following example


routes.MapPageRoute("imprint-designer-url", "imprintdesigner/{product}/{productvariant}/{imprintsystem}", "~/ImprintDesigner.aspx");


but works fine when changed to this


routes.MapPageRoute("imprint-designer-url", "imprintdesigner/{product}/{productvariant}/{imprintsystem}.aspx", "~/ImprintDesigner.aspx");


I have added and verified the following code is present in web.config

<modules runAllManagedModulesForAllRequests="true">


Does anyone have any suggestions or ideas I could try to get this to work?
13 years ago
Nevermind I figured out the problem.

The CommonHelper.IsContentPageRequested() function needed to be changed because it was breaking out of processing for all requests except .aspx, .asmx, etc... I'm sure there is a more elegant way to fix the problem but as a quick fix I changed the code to the following and it seems to function perfectly.



        public static bool IsContentPageRequested()
        {
            HttpContext context = HttpContext.Current;
            HttpRequest request = context.Request;

            if (request.Url.LocalPath.ToLower().EndsWith(".js") ||
                request.Url.LocalPath.ToLower().EndsWith(".css") ||
                request.Url.LocalPath.ToLower().EndsWith(".jpg") ||
                request.Url.LocalPath.ToLower().EndsWith(".gif") ||
                request.Url.LocalPath.ToLower().EndsWith(".png") ||
                request.Url.LocalPath.ToLower().EndsWith(".ico") ||
                request.Url.LocalPath.ToLower().EndsWith(".axd")||
                request.Url.LocalPath.ToLower().EndsWith(".html") ||
                request.Url.LocalPath.ToLower().EndsWith(".pdf")||
                request.Url.LocalPath.ToLower().EndsWith(".zip"))
            {
                return false;
            }

            return true;
        }

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.