tags:

views:

289

answers:

3

For some reason when going back a link, i.e. hitting the back button in your browser takes me to the wrong link in my application. I've got a path of:

http://localhost:3340/Accounts/ContractsControl/GeneralContracts

and on that page I click on a link which takes me to

http://localhost:3340/Accounts/ContractsControl/GeneralContractView/223

now when I hit the back link it takes me to

http://localhost:3340/Accounts/ContractsControl/DataContracts

which is the page I went to the GeneralContracts page from. I'm not entirely sure why this happens, but it means users hitting the back link (which is very common) will get taken to the wrong page.

Global.asax.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using Intranet.AreasLib;

namespace Intranet
{
  // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
  // visit http://go.microsoft.com/?LinkId=9394801

  public class MvcApplication : System.Web.HttpApplication
  {
    public static void RegisterRoutes(RouteCollection routes)
    {
      routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

      routes.MapAreas(
              "{controller}/{action}/{id}",
              "Intranet",
              new[] { "Accounts", "Client" }
        );

      routes.MapRootArea(
          "{controller}/{action}/{id}",
          "Intranet",
          new { controller = "Home", action = "Index", id = "" }
        );

    }

    protected void Application_Start()
    {
      ViewEngines.Engines.Clear();
      ViewEngines.Engines.Add(new AreaViewEngine());

      RegisterRoutes(RouteTable.Routes);
    }
  }
}

Areas by Phil Haack.

FIXED

The JavaScript I did have was something I wrote ages ago and just shoved in there. Being able to click on table rows and redirect to another page which was like follows:

<script type="text/javascript">
    $(document).ready(function() {
      $('tr:not(:has(th))').click(function() {
        window.location.replace("GeneralContractView/" + $(this).attr('id'));
      });
    });
</script>

Whilst this works, it should be like this:

<script type="text/javascript">
    $(document).ready(function() {
      $('tr:not(:has(th))').click(function() {
        window.location = "GeneralContractView/" + $(this).attr('id');
      });
    });
</script>

Because replace doesn't do the same as assigning a new location. It means that the URL referrer is null. Lesson learned.

A: 

I'm guessing it has to do something with your Routes... not quite sure though without seeing the code. Check that your routes are in the correct order that you need them in. Or maybe try creating explicit routes for those actions to see if it makes any difference.

mc2thaH
I've added the routes code, but it's using a custom route system as developed by Phil Haack (I've included the link to his article)
Kezzer
A: 

Are you returning View(), or RedirectToRoute / RedirectToAction in your action? This could happen if you're redirecting silently.

synhershko
Nope, I haven't used RedirectToRoute or RedirectToAction at all yet, just plain old View()
Kezzer
A: 

Could it be client-side, i.e. a JavaScript thing? If you're using an AJAX call or something similar to go from DataContracts to GeneralContractView, then it might be breaking the browser history. I thought most JavaScript/AJAX frameworks had solved this problem, though, so I'm probably barking up the wrong tree! :-)

alastairs
Nope, not using anything like that at all. It's quite a barebone application at the moment.
Kezzer
I apologise, I jumped to a conclusion there and forgot about something. I was using table row clicks for redirections in JavaScript. Check my edit to see in a mo'
Kezzer