C # MVC RouteBase routing too many redirects

2

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

My problem now is when I try to access a page it returns 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 schedules or views the voucher;

If the user tries to return to the home page either by using the back button or by changing the URl it falls into a redirect loop, this occurs because on the scheduling and voucher pages I have a check session, if it is null I make the redirect back to the beginning (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 strange is that when he tries to change the page RouteBase tries to retrieve the information of this new URL and at this moment for some reason it ends up getting the same page, of scheduling, instead of the page of form and then the whole looping begins.

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

I filled in the form, it fell on the schedule and I went to the voucher, tried to return loop, wait and give a refresh, load the page normally.

As the code is kind of extended I put it in a bin: link

And also has the headers of requests:

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 vars checking (I have about 6k routes within the pageList) I found out that the problem is being checked for value and updating the variable.

In line 128 of the pastebin file I get a list of routes and I search within it the route that interests me, in 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 "generic" route for the three areas (form, scheduling and voucher) I need to put the Controller and Action I want. At this point I'm updating a local variable, but I end up also updating the parameter pageList .

I've also tried to put another variable pages inside the method of line 128, copy the pageList to it and then perform the search inside it. pageList also ends up being refreshed just like Cache, line 202.

What might be causing this?

    
asked by anonymous 26.11.2015 / 14:00

1 answer

1

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

If the clone is not used the value copied from a Cache will maintain a "referral link", and so when I was editing some information on the routes it was applying this change to the cache and thus falling into a loop of redirect.

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 path is generic (same route as 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 the action Index and when it fell on the check of a Session it did the redirect.

As I explained above, I was able to solve the problem by implementing Clone for these objects, I updated my doc in PasteBin ( link ) someone wants to understand how it works.

    
30.11.2015 / 20:27