2

I'm facing an issue in a project that I'm currently working on, I'm using ASP.NET MVC.

The scenario as follow:
- I have a login page (Username and Password).
- Whenever I navigate to localhost:5588/login, the below action method will be called 2 or 3 times (I'm using a Break Point inside this method to catch the call).

public ActionResult Login()
{
     return View();
}

The question is, why this method is called 2 - 3 times whenever I enter the login page ?

P.S #1: Not only the Login page is being called 2-3 times, also each Action method have the same issue.
P.S: #2: I'm using the below route:

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

    routes.MapRoute(
        name: "Default",
        url: "{controller}/{action}/{id}",
        defaults: new { controller = "Login", action = "Login", id = UrlParameter.Optional }
        );       
}

UPDATE:
This issue happens only on Google Chrome!

Mohammad Alqurm
  • 577
  • 6
  • 23
  • If you were using the Default route, then `localhost:5588/login`would never hit that method (it would go to the `Index()`method of `LoginController`) –  Jan 31 '17 at 10:01
  • 1
    @MohammadAlqerm what is the LoginView doing? Can you post the code? – peval27 Jan 31 '17 at 10:08
  • @peval27: The Login view contains only username and password, plus a CAPTCHA area. But the issue is not only in the Login action method, this behavior happen in each action method call in the whole project. – Mohammad Alqurm Jan 31 '17 at 10:31

4 Answers4

2

Issue might happen, because browser can pre-load page, before you hitting Enter. In this thread posted solution, how you can understand that it is pre-load request: HTTP header to detect a preload request by Google Chrome

Community
  • 1
  • 1
Victor Leontyev
  • 8,488
  • 2
  • 16
  • 36
1

Obviously somethings call your action method 3 times, strongly advice to open chrome developer tools, navigate to network and check the traffic, if they are XHR requests you can also track from where they came from, otherwise it is shoot in the dark.

Ľuboš Pilka
  • 1,044
  • 1
  • 11
  • 17
1

I once had this issue and found I had something like this

src="#"

in my image tag or check for any other markup that could be accidentally referencing the page like Script references, image references, css reference etc

Bits_Please
  • 546
  • 1
  • 5
  • 13
0

This is the correct answer and this actually solved the issue. [Special Thanks to my friend Mohammad Aldayem for the great finding].

Based on an issue posted on Chromium Issue Tracker (https://bugs.chromium.org), the issue was in the "favicon.ico" in the _Layout.cshtml page. Because Chrome requests favicons on every request on pages that don't have a favicon.

And here are the links for this issue while using Google Chrome:

Link #1: https://bugs.chromium.org/p/chromium/issues/detail?id=64810
Link #2: https://bugs.chromium.org/p/chromium/issues/detail?id=39402

Mohammad Alqurm
  • 577
  • 6
  • 23