HttpContext.Current.Request与Angular UI路由器
问题描述:
使用Asp.Net我正在捕获请求的AngularJS
路由,因为它加载。路线是/FST/#/quickstart
。我试图捕捉这条路线有:HttpContext.Current.Request与Angular UI路由器
var currentUrl = HttpContext.Current.Request.RawUrl;
然而,RawUrl
不包含#/quickstart
分部。在请求中似乎没有任何东西可以告诉我完整的URL。我如何获得目标网址?
答
您可以使用$http
拦截到当前路线作为头添加到您的Web API请求
$httpProvider.interceptors.push(['$q','$location' function($q, $location) {
return {
'request': function(config) {
config.headers.ClientSideUrl = $location.path();
return config || $q.when(config);
},
'requestError': function(rejection) {
return $q.reject(rejection);
},
'response': function(response) {
return response || $q.when(response);
},
'responseError': function(rejection) {
return $q.reject(rejection);
}
};
}]);
,然后访问标题服务器端:
HttpContext.Current.Request.Headers.GetValues("ClientSideUrl").FirstOrDefault();
你不可错过' #“在服务器的URL中。 – DavidG 2014-10-01 12:30:17
可能的重复[什么是URL中的#号](http://stackoverflow.com/questions/7909969/what-is-the-symbol-in-the-url) – DavidG 2014-10-01 12:31:23
获取哈希值没有意义当我们使用angularJs进行开发时,部分在服务器端。散列'应该用于在客户端执行路由,这可能会将解析的参数(如果有的话)发送到服务器端。 – 2014-10-04 03:05:41