Friday, June 24, 2011

IE Tries to Download Json Response

Apparently, IE 8 and below doesn't like "application/json" mime type in ajax response. When it receives the response, it tries to download it as a file, and prompts a "Save as" dialogue. Although the standard json mime type is "Application/json", you need to use "text/plain" to fix this issue, So if you are using .Net MVC you need to use:
return Json(result, "text/plain");

Where "result" is the object you want to convert to Json.

Important: Do not use "text/html", it creates an XSS flaw in your application. See here for more info

Thursday, June 23, 2011

Regex For Matching File Names with Date

Here is some example of file name matching regex:

File Format:

FileName-dd-mm-yyyy.EXT:
^(FileName)-([1-9]|0[1-9]|[12][0-9]|3[01])-([1-9]|0[1-9]|1[012])-(19[0-9][0-9]|20[0-9][0-9])\.EXT$

See here for a good reference: http://msdn.microsoft.com/en-us/library/az24scfc.aspx
Also you can test your expression here: http://www.regextester.com/