Publish my webapi project aspnet web api angularjs - angularjs

I want to publish my project to a folder in IIS but with the routes setup the way it is I get what looks like an internal loop and not finding the path.
I published the project in a folder already
angular.module("common.services", ["ngResource"])
.constant("appSettings",
{
//serverPath: "http://localhost:53967/"
//name of the computer and folder to which the project was published
serverPath:"http://ct-dx-ariang/AspNetWebApi/"
});
And have a resource setup as follow
angular.module("common.services").factory("productResource", ["$resource", "appSettings", productResource])
function productResource($resource, appSettings) {
//return $resource(appSettings.serverPath + "/api/products/:search");
return $resource(appSettings.serverPath + "/api/products/:id"
These are my routes
$urlRouterProvider.otherwise("/");//default url
$stateProvider.state("home", {
url: "/",
templateUrl: "/templates/welcomeView.html"
}).state("productList", {
url: "/products",
templateUrl: "/templates/productListView.html",
controller: "ProductListController"
}).
How can I modify this sample project so that it runs in the published folder on the IIS as opposed to in localhost on visual studio?

A slash at the beginning of a path makes that path relative to the root of the site. So in your case:
templateUrl: "/templates/productListView.html"
will always refer to http://myhostname/templates/productListView.html, no matter in which subpath is hosted your site.
Removing the first slash may solve your issue:
templateUrl: "templates/productListView.html"
Also looking at your $resource configuration:
return $resource(appSettings.serverPath + "/api/products/:id"
And your AppSettings constant:
serverPath:"http://ct-dx-ariang/AspNetWebApi/"
Seems to me that you are adding two consecutive slashes to your $resource path. The resulting path will be: http://ct-dx-ariang/AspNetWebApi//api/products/:id

These are my routes
Pretty hardcoded. Make sure that you use the same constant over there for all your templates as well.
templateUrl: appSettings.serverPath + "/templates/welcomeView.html"

Related

Google App Engine dispatch.yaml Unexpected attribute 'service'

I am having some trouble getting my dispatch.yaml file to run on the local devappserver. I have had two errors one seems to be related to indentation
expecting <block end>, but found ? I can fix this by removing the indentation as shown below in my dispatch file.
The second problem happens when I have removed the indentation I get Unexpected attribute 'service' of type DispachInfoExternal I have tried copying the example from the google docs but I get the same error, I have also tried changing the name service to module as I believe that was the old name and I get the same error. I am using Atom as my editor.
dispatch:
- url: '*/content/*'
service: default
- url: '*/admin/*'
service: admin-services
- url: '*/creator/*'
service: creator-services
- url: '*/social/*'
service: social-services
- url: '*/subs/*'
service: subscription-services
- url: '*/user/*'
service: user-services
You're missing the indentation from the yaml files.
It's different writing
dispatch:
- url: '*/content/*'
service: default
than
dispatch:
- url: '*/content/*'
service: default

proper url encoding for angularjs routing

I have angularJS app using ASP MVC WebAPI. I need to get a code for resetting the user password.
My routes look like this
$routeProvider.when("/reset/:token", {
controller: "loginController",
templateUrl: "/app/views/reset-password-confirm.html"
});
This works:http://localhost:32150/#/reset/AQAAANCMnd8BFdERjHoAwE2FCl2BsBAAAA9pA7cuLEnE6SqyFKTJPlewAAAAACAAAAAAAQZgAAAAEAACAAAAA9GudF4k3KPq1IeOc12moCFFCK80GiVLfQ43LoGgDHawAAAAAOgAAAAAIAACAAAACXlb8kgEE5kb2F2Bnqw1iSins5FyeuzlVOEc12BTtM71OXHAAAABWN9RxDvdzSQUTe2NrvYF6OCw2aQh1HiyBYGbQFhvtaJc3AX71EGAHLvsbIpWv9kgcKkrI9mhSmeCdguT9qQTpURIMulrTFg0z3Y0fEtB6FJHNq7P9S2pGRyCoon3sk2BNUfBamE3Pye2ND3qJfteM2BQAAAAJ17NJK5Nn98CSH4Q8uT5Txj8yHpV6xFVJ2e0Q9At2Bv4YV5r5I0kPdVejBA1WJMLvoJ6l0R5p3R2kXsj73M323I3D
but this doesn't: http://localhost:32150/#/reset/AQAAANCMnd8BFdERjHoAwE%2FCl%2BsBAAAA9pA7cuLEnE6SqyFKTJPlewAAAAACAAAAAAAQZgAAAAEAACAAAAA9GudF4k3KPq1IeOc12moCFFCK80GiVLfQ43LoGgDHawAAAAAOgAAAAAIAACAAAACXlb8kgEE5kb%2F%2Bnqw1iSins5FyeuzlVOEc1%2BTtM71OXHAAAABWN9RxDvdzSQUTe2NrvYF6OCw2aQh1HiyBYGbQFhvtaJc3AX71EGAHLvsbIpWv9kgcKkrI9mhSmeCdguT9qQTpURIMulrTFg0z3Y0fEtB6FJHNq7P9S2pGRyCoon3sk%2BNUfBamE3Pye2ND3qJfteM%2BQAAAAJ17NJK5Nn98CSH4Q8uT5Txj8yHpV6xFVJ2e0Q9At%2Bv4YV5r5I0kPdVejBA1WJMLvoJ6l0R5p3R2kXsj73M323I%3D
I noticed that if I remove % the route works but since the token string has characters like / I have to find a way of encoding it.
Any way I can encode the string in ASP MVC webAPI so that it works in AngularJS?
It might be a security issue. Try adding relaxedUrlToFileSystemMapping in your web.config. For example:
<system.web>
<httpRuntime targetFramework="4.5" relaxedUrlToFileSystemMapping="true" />
</system.web>
$routeProvider.when("/confirm_email/:token*", {
controller: "signupController",
templateUrl: "/app/views/confirm-email.html"
});
Adding the * character to the end of the route will make the code work as expected.

Ext MVC does not load all folders and source files

I'm new to Ext and it's my first contact with this framework and I'm creating java web app. Here is my folder structure:
src
--main
--webapp
--index
--application
--controller
--Index.js
--model
--store
--view
--MainPanel.js
--Index.js
--resources
--WEB-INF
--Index.jsp
Here is webapp/Index/Index.js
Ext.application({
name: 'Spring_Ext',
appFolder: '/index/application',
controllers: [
'Index'
]
});
And here is webapp/index/application/controller/Index.js
Ext.define('Spring_Ext.controller.Index',{
extend: 'Ext.app.Controller',
views: ['MainPanel'],
init: function(){
....
}
....
});
When I run it on tomcat in chrome I get error saying it cannot found(404)
GET http://localhost:8081/index/application/controller/Index.js?_dc=1425849848988 ext-all-debug.js:6262
and when looking in source tab in chrome developer in index folder there isn't application folder with MVC structure, but only Index.js.
Thats because at the index.js level of your directory structure you are already in /index/application/
Extjs is now looking for the same path and cannot find it. Instead just specify '/' for you appFolder config. You might even not need to set this as it may default to this already
No need for appFolder. And in your source tab there is no application folder with mvc because your controller hasn't loaded successfully. Try giving the whole path of MainPanel in our controller like this
Views: Spring_Ext.view.MainPanel

Configure beego.Router to serve index.html for AngularJS non-server routes

I have a route beego.Router("/", &controllers.MainController{}) where it serves the index.html and all other routes are server APIs such as beego.Router("/api/products", &controllers.ProductController{}).
How to configure the beego's router to serve index.html for all others routes that supposed to be handled by ui-router in angularjs such as /products?
beego.Router("/", &controllers.MainController{}) or beego.Router("", &controllers.MainController{}) doesn't work
In my case, I solved the problem by adding following route to my path
beego.Router("/*", &controllers.MainController{})
type MainController struct {
beego.Controller
}
func (c *MainController) Get() {
c.TplName = "index.html"
c.Render()
}
Simply it returns index.html for any other path and angularjs deal with the rest.

Angularjs - failed to load template - url is close, but missing the virtual directory name

I have deployed my angular application across 2 load balanced web servers. Sometimes the templates load up, other times they don't, as the url is wrong - the virtual directory name is missing.
Looking at the headers for the template request, I can see the referer is
http://mysite/folderInIIS/VirtualDirectoryName
when the templates are searched for the Request URL used is
http://mysite/folderInIIS/Templates/myTemplate.html
which fails
If I edit this to:
http://mysite/folderInIIS/VirtualDirectoryName/Templates/myTemplate.html
I find my template.
So, because this is periodically occurring, I think one of the web servers has been set up incorrectly, and the load balancer will determine which one you go to and whether or not you will see the error.
But what would cause the template url to be crafted without the virtual directory name in the path?
A cut from my directive showing the templateUrl:
return {
restrict: 'E',
scope: {split : '&', collapseUp: '&', collapseDown: '&'},
replace: true,
transclude: true,
templateUrl: 'Templates/collapseTemplate.html',
controller: ['$scope', '$rootScope', '$timeout', function ($scope, $rootScope, $timeout) {
var panes = $scope.panes = [];
var splitterControl;
You need to define <base href="..." /> in the` section of the page, like:
<base href="http://mysite/folderInIIS/VirtualDirectoryName" />
Of course if you want it work on both the local testing environment (no virtual directory) and the server (in virtual directory), you need to dynamically compute the base href.
For example, in .NET MVC, you can use:
<base href="#Url.Content("~")" />
Hope it helps.

Resources