2

We have a website running ASP.NET MVC 4 which would occasionally show the HTML page source when loaded, instead of the output generated by the view + controller. Restarting the associated Application Pool fixes this until it randomly happens again.

The web server is an AWS EC2 instance running on Windows 2012. Trying to Google this turned out to be in vain. Has anyone experienced this and knows what's the cause and how to fix this?

Thanks.

ckng
  • 545
  • 1
  • 5
  • 16
  • are you by any chance doing double HTML Encoding ? – Gopesh Sharma Feb 15 '17 at 05:33
  • [This answer](http://stackoverflow.com/a/1193746/5621607) should fix your issue! – ViVi Feb 15 '17 at 05:34
  • Probably need more info if possible - content-type returned to client? Any "front end" resources in between (e.g. WAF, LB, caching systems) that might come into play? – EdSF Feb 15 '17 at 06:30
  • @GopeshSharma No, otherwise restarting the app pool wouldn't have helped. The entire page source, including the doctype and tag are displayed in raw. It's as if you did a view source. – ckng Feb 15 '17 at 09:42
  • @EdSF Our site runs on 2 EC2 instances behind an AWS Elastic Load Balancer (ELB). Usually one of the servers will exhibit this at a random time. There is no regularity between which server the problem happens on, it can be one or the other. I'll need to check the content-type the next time it happens again. – ckng Feb 15 '17 at 09:44
  • That's probably a good place to _start_ the hunt - it seems the client is being sent _text_ (`text/plain`), or something other than `text/html`. In the above, when you say "source" - _source code_ (as in with `razor` markup) or the rendered/resulting html? It could help further pin down "where" (things are failing). Hth... – EdSF Feb 15 '17 at 17:05
  • @EdSF It's the generated HTML code, not the razor markup. Your suspicion that it might be sending as text/plain sounds plausible. How can I prevent this from happening randomly? – ckng Feb 16 '17 at 01:48
  • Tough _guess_ - your app _seems_ fine (render's properly) unless there's some code that affects `content-type` http headers in your app sent to client or some `mime` type not being handled properly on those "specific times". That said http header re-writing/modification in some intermediate resource (lb, waf) is another. But all this is just guessing...hth... – EdSF Feb 16 '17 at 01:58
  • Is there any script or ajax call that is returning your view? If yes, check what is the data type being returned from there. – Utkarsh Bais Feb 16 '17 at 19:40

0 Answers0