Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC3 - Controller index action called twice every time

Using MVC Razor I have a very simple test. The "logger" writes messages to a log file

TestController.cs

public ActionResult Index()
{
  logger.Trace("Test Index Called");
  return View();
}

Index.cshtml

<html>
<head><title>Testing</title></head>
<body><h3>This is a test</h3></body>
</html>

global.asax.cs

routes.MapRoute(
  "Default",
  "{controller}/{action}",
  new { action = "Index" }
);

When I run the code, the log file shows this:

2011-12-15 10:16:09.4475: Test Index Called

2011-12-15 10:16:09.4475: Test Index Called

Notice that the timestamp for both calls are at exactly the same time? I've eliminated the issue where people have said that empty src attributes on a image tag and/or javascript functions not returning.

I've made this as simple as I possibly can - but the index action is being called twice in rapid succession.

Help?

like image 380
JayTee Avatar asked Nov 14 '22 12:11

JayTee


1 Answers

Are you 100% sure that it's not the logger that writes two entries for each call? (For instance if you have configured two filters for the same logging target)

It's highly unlikely that ASP.NET can process the same action two times at the exact same millisecond.

like image 136
jgauffin Avatar answered Dec 07 '22 19:12

jgauffin