odoe

MVC4 Web API and Dojo Config

Discussion created by odoe on Jan 17, 2013
Latest reply on May 22, 2014 by ajmorris
Ok, this is killing me.
I recently started usiing MVC4 and the new Web API to build an app. Everything works great when running in Visual Studio and even works fine when running from my deployment server if I access the url as localhost/application, but once I change to the site name //<servername>/application it looks like the regex for loading modules with Dojo CDN break.

Here is my main.js
(function () {
    'use strict';

    var root = this;

    require({
        async: true,
        parseOnLoad: true,
        aliases: [["text", "dojo/text"]],
        packages: [
          {
              name: "views",
              location: location.pathname.replace(/\/[^/]+$/, "") + "Scripts/app/views"
          }, {
              name: "models",
              location: location.pathname.replace(/\/[^/]+$/, "") + "Scripts/app/models"
          }, {
              name: "helpers",
              location: location.pathname.replace(/\/[^/]+$/, "") + "Scripts/app/helpers"
          }, {
              name: "widgets",
              location: location.pathname.replace(/\/[^/]+$/, "") + "Scripts/app/widgets"
          }, {
              name: "app",
              location: location.pathname.replace(/\/[^/]+$/, "") + "Scripts/app"
          }
        ]
    }, ['app/run']);


}).call(this);


I am not using the bundler for my modules

Here is my Script Render function on my cshtml file
        @Scripts.Render("~/bundles/jquery",
        "~/bundles/jqueryui",
        "~/Scripts/toastr.js",
        "//serverapi.arcgisonline.com/jsapi/arcgis/?v=3.3compact",
        "~/Scripts/app/main.js");


The error I get is
http://serverapi.arcgisonline.com/jsapi/arcgis/3.2compact/js/dojo/dojo/Scripts/app/run.js 404 (Not Found) 


So for some reason, it looks like location.pathname.replace() regex isn't working when using the servername, but is fine when using localhost.

If anyone has deployed successfully a MVC4 app in this manner, I'd appreciate any help. As it is, I'll need to work on reworking this as a non-MVC4 app in the meantime.

Outcomes