0

Following is the exact scenario in my application:

  • I generate a GUID in an controller action.
  • The GUID is stored in TempData.
  • I pass the GUID along with a ViewModel in a razor view (MyView.cshtml) that gets opened from that controller action.
  • A view is having a hiddenfield which is bound with the GUID.

    @Html.HiddenFor(m => m.CustomGuid)
    
  • There is another controller action which returns a Json result containing the GUID value in TempData.

    [HttpGet]
    public ActionResult GetGuid()
    {
        string result = String.Empty;
        if (GetTempData("mGuid") != null)
        {
           result = GetTempData("mGuid").ToString();                
        }
        else
        {
          result = "INVALID_SESSION";
        }
        return Json(result, JsonRequestBehavior.AllowGet);                
     }
    
  • I have written following jquery in MyView.cshtml

$.get('@Url.Action("GetGuid", "Controller")', function (result) {

if (result.toString().toLowerCase() == $('#CustomGuid').val().toString().toLowerCase()) {
alert('ok');
            }
            else {
                alert('Invalid Identifier.');
                window.location = '@Url.Action("ShowErrorPage", "Controller")';
                return false;
            }
        });

The problem is that, it works fine in IE and Firefox, but it always has a different GUID in the TempData and HiddenField, and so everytime giving a message of "Invalid identifier"

What could be the reason? Why this behavior could be different in Chrome?

Amit
  • 15,217
  • 8
  • 46
  • 68
Nirman
  • 6,715
  • 19
  • 72
  • 139
  • You should check if chrome doesn't do a request in between for 'something', since TempData only is present until the next request. The behaviour you describe (`GetGuid()` returning `"INVALID_SESSION"`) seems to suggest that anyway. – Major Byte Apr 30 '13 at 05:34
  • I tried putting the alert in the javascript function, and it is showing different GUIDs for TempData and HiddenField readings, and "Invalid_Session" is not getting shown for any of them either... – Nirman Apr 30 '13 at 06:10
  • Is it possible that Chrome might be doing a request in between, whereas IE and Firefox aren't doing any such request? – Nirman Apr 30 '13 at 06:12
  • that's what i asked you to check, yeah... If the GetGuid method returns a new GUID/different one, then when does this different one get set? – Major Byte Apr 30 '13 at 06:22
  • A new GUID gets set each time a controller action gets called. (say Index is the main controller action which sets the new GUID, and launches the view (MyView.cshtml) immediately. There is no other request in between. – Nirman Apr 30 '13 at 06:25

1 Answers1

0

I found that, a resource (simply a light-weight CSS) file was missing on the server. However, that CSS had no significance in the website, but Chrome reloads the page if any of the resource is not found, whereas IE and Firefox simply ignores. Having said that, I could manage to fix this by removing reference of that CSS (which was absolutely not required in my application)

Nirman
  • 6,715
  • 19
  • 72
  • 139