BuildOurOwnBabylonJSController.cs 797 B

12345678910111213141516171819202122232425
  1. using System.Web.Mvc;
  2. using System.IO;
  3. using System.Text;
  4. namespace BuildOurOwnBabylonJSServer.Controllers
  5. {
  6. public class BuildOurOwnBabylonJSController : Controller
  7. {
  8. public const string GetFileContentActionName = "GetFileContent";
  9. [ActionName(BuildOurOwnBabylonJSController.GetFileContentActionName)]
  10. public ActionResult GetFileContent(string rootPath, string relPath, string type)
  11. {
  12. var babylonJSPath = Path.Combine(Server.MapPath("~"), rootPath);
  13. var absPath = Path.Combine(babylonJSPath, relPath);
  14. var streamReader = new StreamReader(absPath, Encoding.UTF8);
  15. var text = streamReader.ReadToEnd();
  16. streamReader.Close();
  17. return Content(text, type);
  18. }
  19. }
  20. }