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.
Related
I have a spring boot app and a controller that server static webpage(React build):
#Controller
#RequestMapping("/test")
public class HomeController {
#GetMapping("/")
public String index() {
return "index.html";
}
...
index.html is located at: ../resources/static/index.html
also in application.yml:
spring:
mvc:
static-path-pattern: /test/**
I am having two problems(problem 2 is the main issue):
I must call the following url with the trailing '/' at the end: http://localhost:8100/test/ I would like for http://localhost:8100/test to also map me to the view(index.html).
during the load of the page I am getting the following error:
the problem as you can see is that the url called is:
http://localhost:8100/static/css/main.6c417d20.chunk.css
and not
http://localhost:8100/test/static/css/main.6c417d20.chunk.css
(please note that the reason for the 'static' in the url is that there is a folder named: static below the resources/static folder so there is no issue with the 'static' in the url)
is it a server side problem or is it something I should fix in the react?
I searched for an answer but didn't find anything helpful.
any help would be highly appreciated,
Tnx
So the answer to my question lies in the following links:
how to build react to a non root path(homepage):
build react non root path
registering zuul client to the following path(that contains all resources):
Zuul configuration with resources
so I am leaving this here in case someone has the same issue(the answer in the second link is for vue.js and webpack,the first link explains how to change root address in react).
Answer 1 : #RequestMapping has a String[] value parameter, so can specify multiple values like this:
#RequestMapping(value={"", "/", "welcome"})
Answer 2 : You are expecting test in URL which is controller mapping not the project context path so it should not come in static resources urls.
see this answer for more clarity adding css and js in spring boot.
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"
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.
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.
I have a Web API 2.0 service which defines a particular route:
/api/someEntityGroup/{entityName}
I'm calling this enpoint using Angular $resource service.
The problem is when user wants to provide an entity name with characters that have a specific meaning in URL:
404 Not found - . (full stop), /, +
400 Bad request - ?, :, &, %, *, <, >
And these are the ones I've encountered. There may be others that may be problematic as well and I'm not even aware of them (yet).
If I use window.escape() function these still don't work, but I mainly get 404 back (the only exception being * which still returns 400 Bad request).
My code
Angular resource creation:
.factory("entityResource", ["$resource", function() {
return $resource("/api/entities/:id", null, {
search: {
method: "GET",
url: "/api/entities/:name",
isArray: true
}
});
}]);
How I call it in my code:
entityResource.search({ query: scope.name }, function(data) {
...
});
My Api controller action:
[RoutePrefix("/api/entities")]
public class EntitiesController: ApiController
{
[Route("{searchQuery}")]
public IEnumerable<Interest> Get(string searchQuery)
{
return this.interestService.Search(searchQuery);
}
...
}
I can shed some light on your 404 Not found issue when using ., /, + characters.
The issue isn't with Angular but rather with Web API and the way it resolves routes. Urls that Web API interprets as being managed resources (e.g. static content, pages etc.) it will try to resolve independently.
Set the following in your web.config to disable this behavior and force WebAPI to run all requests through your modules:
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
Just a warning - If your Web API is hosted together with something like MVC or a static website, the above is not recommended as it will force all managed resources (pages, MVC routes, content[css,js,images]) through your API modules and there will be a performance impact. However, if all the API is doing is serving resource routes I would recommend enabling the above.