mardi 1 décembre 2015

C# MVC RouteBase routing too many redirects

I have this custom routing system where i will get the paths, controllers, views and areas from my DB and set them according to the requested path.

My problem right now is that when i try to access one page it gives me the too many redirects response.

What happens in this area is:

  • User access page and fill a form;
  • Form is posted using AJAX and then a redirect is made from jquery;
  • User makes an appointment or generate a voucher;

If the user tries to return to the previous page by typing it on the browser( i don't have any button to that link ) he gets the too many redirects problem.

Since the code is kind of big i'm going to post it here: http://ift.tt/1Tf7nxO

I only left out my DB logic.

What could be doing this ? I only could see the problem in this area but i don't know for sure it isn't happening in other areas.

EDIT

These are the headers from the 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 2

After much debugging and logging i found the beginning of the problem, it's related to a redirect i have when a certain session is null:

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

    return null;
}

I have this verification at the appointment and voucher, if he tries to reload the page he is redirected to the form page. Now what is weird is, when he changes URL the RouteBase executes and tries to fetch the PageInfo( VirtualPath, Controller and View ) for that new URL and at the moment of my search for some reason i'm getting the page of appointment instead of the form one so i get back at the same page and the looping starts.

I have updated my pastebin with the filtering and DB Search, there are no repeated records in my DB. It looks like some sort of freaking cache but the var is local and there's no sharing.

EDIT 3

After some var watching ( i have nearly 6k routes ) i found that the problem lies between my route checking on the pastebin file on line 128, that pageList parameter is my list of all routes from the cache, i do a url search based and then i take the route that i need, on line 167 is where my problem is located. At that moment i have copied the content of the route i want into my freakingPage var (not so cool, i know) and then i change the values of Action and Controller but what also happens is the value changes on the pageList var and also at the Cache, line 203.

What could be causing this ?

Aucun commentaire:

Enregistrer un commentaire