torsdag den 26. marts 2015

Define extra MIME types in web.config to accecpt fx. .json file like .txt file

If you want to have filename as my.json instead if my.txt file - you will have the problem that server don't know how to response for request for my.json as it don't know the type.
You can define the type (MIME)  in the web.config file.

Example for accept .json to be handlet like .txt file.

<configuration>
........................
   <system.webServer>
   .......................
        <staticContent>
             <mimeMap fileExtension=".json" mimeType="application/json" />
        </staticContent>
   ........................
   </system.webServer>

........................
</configuration>​

Thank Vigan S for the input.

How to make WCF service available for JavaScript from for foreign server

Normaly you could not make XMLHttpRequest in JavaScript to a service on another server.

If you have access to change the Web.Config on the server you want til make request to, you can set up some extra information for the http header to make request possibly.

Example - part of Web.Config file

<configuration>
......
   <system.webServer>
......  
    <httpProtocol>
      <customHeaders>
        <add name="Access-Control-Allow-Origin" value="*"/>
        <add name="Access-Control-Allow-Headers" value="Content-Type, Accept" />
        <add name="Access-Control-Allow-Methods" value="POST,GET,OPTIONS" />
        <add name="Access-Control-Max-Age" value="1728000" />
      </customHeaders>
    </httpProtocol>
......  
   </system.webServer>
......  
</configuration>

You can find more information here:
Description in details:

Thank you Jeppe B for the solution.

søndag den 15. marts 2015

Scale HTML page to fill screen on mobile device

When you watch a HTML page on a mobile device you might want the size til scale to the screensize.
This can be done by placing meta information viewport in html head and set the scale to 1.
For half size set scale to 0.5

<head>
.......
<meta name="viewport" content="width=device-width, initial-scale=1" />
......
</head>