I am triyng to run a little MelonJS Game in a ASP.NET MVC 4 Razor Page. First of all, I think it is possible to fix this without any MelonJS knowledge (only MVC 4).
The problem is:
At one moment, MelonJS need to load some files from the server (I put the files in Content/data/[..]/file.ext). To do this it performs for each file a HTTP GET on localhost:XXXX/%EveryThingIWant/file.ext%.
Of course, it fails. I try to enable DirectoryBrowsing but it did not solve the problem. In order to get it working quickly, I did this (I'm not proud of it, it's just a quick fix):
I create a new action in one of my controllers:
//
// GET: /Game/Data
public FileResult Data(string path)
{
string physicalPath = Server.MapPath("~/Content/" + path);
byte[] fileByte = null;
using (FileStream fs = new FileStream(physicalPath, FileMode.Open))
{
fileByte = new byte[fs.Length];
fs.Read(fileByte, 0, (int)fs.Length);
}
var result = new FileContentResult(fileByte, "tmx");
return result;
}
And I set the %EveryThingIWant/file.ext% to "Game/Data?path=[..]/file.ext".
It works but I am wondering if there is not a better solution to perform that. Put the file in an other folder? I tried to enable DirectoryBrowsing and adding a MIME type but I failed util now. It is possible?
I don't know if it's the good way but this is what I've finally done :
-I put the data in a specific folder (I chose App_Data but I don't know if it's the good place for that)
-I put a Web.config in this folder with that content :
(I guess I have to specify all custom extension)
-In my case (App_Data folder), I had to add in the global Web.config :
With these modifications, the HTTP GET on my resources works well.