C# MVC Routebase routing Too Many Redirects

Asked

Viewed 620 times

2

I have an all dynamic system where I get all my paths, controllers, views and areas from the BD.

My problem now is when I try to access a page it returns to me too many redirects response.

What happens in this area is:

  • User fills in a form;
  • The form is posted via AJAX and the user is redirected via Jquery;
  • The user then makes a schedule or views the voucher;

If the user tries to return the home page either by using the back button or by changing the Url it drops into a loop of redirect, this is because on the scheduling and voucher pages I have a Session check, if it is null I do the redirect back to the start(form), this is the redirect check:

if (TempData["LeadID"] == null || Session["UnidadeCE"] == null)
{
    Response.Redirect( HelperMethods.CreateLink( Request.RawUrl.TrimStart( '/' ).Split( '/' )[0] ) );
    Response.End();

    return null;
}

Now, what’s weird is that when he tries to change the page RouteBase tries to retrieve the information from this new URL and at this point for some reason he ends up taking the same page, scheduling instead of the form page and then starts the whole looping.

The worst is that this only happens the first time, for example:

I filled out the form, dropped in the schedule and went to the voucher, tried to return drops in loop, hope and give a refresh, loads the page normally.

Since the code is kind of extensive I put it in a bin: http://pastebin.com/yTdWKMp4

And there are also requests headers:

HTTP/1.1 302 Found
Cache-Control: private, no-store, max-age=1
Content-Type: text/html; charset=utf-8
Content-Encoding: gzip
Expires: Wed, 25 Nov 2015 19:01:23 GMT
Last-Modified: Wed, 25 Nov 2015 19:01:22 GMT
Etag: ""
Location: /teste-lp
Server: Microsoft-IIS/8.0
X-AspNetMvc-Version: 3.0
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
X-UA-Compatible: IE=Edge,chrome=1
Date: Wed, 25 Nov 2015 19:01:22 GMT
Content-Length: 115

HTTP/1.1 200 OK
Cache-Control: private, no-store, max-age=1
Content-Type: text/html; charset=utf-8
Content-Encoding: gzip
Expires: Wed, 25 Nov 2015 19:02:10 GMT
Last-Modified: Wed, 25 Nov 2015 19:02:09 GMT
Etag: ""
Server: Microsoft-IIS/8.0
X-AspNetMvc-Version: 3.0
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
X-UA-Compatible: IE=Edge,chrome=1
Date: Wed, 25 Nov 2015 19:02:12 GMT
Content-Length: 6852

EDIT

After a lot of debugging and checking of vars ( I have about 6k routes inside pageList ) I discovered that the problem is being to check the value and update the variable.

On line 128 of the archive of the Pastebin I get a list of routes and look inside it for the route that interests me, on line 167 is the case of the voucher, I check if it has this name in the URL and look for the correct route, as this is a route "generic" for the three areas ( form, scheduling and voucher ) I need to put the Controller and Action that I want. At this moment I am updating a local variable, but I end up updating the parameter as well pageList.

I’ve also tried to put another variable pages within line 128 method, copy the pageList for her and then carry out the search within her. the pageList also ends up being updated as well as Cache, line 202.

What could be generating this ?

1 answer

1


After a little searching I discovered that my problem was actually related to the . NET cache, I had not used the method clone.

If the clone is not used the value copied from a Cache will maintain a "reference link", and with that when I was editing some information on the routes he was applying this change to the cache and with that falling into a redirect loop.

In my case this happened because in order to fall on the scheduling page I need to change the value of Action because the registration route is generic ( same route existing in the BD server for registration, scheduling and voucher ), when I changed the value the original route was always pointing to the Action Scheduling instead of action Index and when I fell into a Session check it would redirect.

As I explained above, I was able to solve the problem by implementing the Clone for these objects, updated my doc in Pastebin ( http://pastebin.com/yTdWKMp4 ) if someone wants to understand how it works.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.