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);
}
}
}
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.