简体   繁体   English

带有Angular UI路由器的HttpContext.Current.Request

[英]HttpContext.Current.Request with Angular ui-router

Using Asp.Net I am capturing the request of an AngularJS Route as it loads. 使用Asp.Net,我正在捕获AngularJS路由的请求。 The route is /FST/#/quickstart . 路由是/FST/#/quickstart I am trying to capture that route with: 我正在尝试通过以下方式捕获该路线:

var currentUrl = HttpContext.Current.Request.RawUrl;

however, the RawUrl doesn't contain the #/quickstart subpart. 但是, RawUrl不包含#/quickstart子部分。 There doesn't seem to be any thing in the Request than can tell me the full URL. 要求中似乎没有什么可以告诉我完整的URL。 How can I get the target URL? 如何获得目标URL?

You Can use a $http interceptor to add the current route as a header to your web api request 您可以使用$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);
            }
        };

    }]);

And then access the header server side: 然后访问标头服务器端:

HttpContext.Current.Request.Headers.GetValues("ClientSideUrl").FirstOrDefault();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 生产中的HttpContext.Current.Request为null - HttpContext.Current.Request null in production 在HttpContext.Current.Request中模拟ServerVariables - Mock ServerVariables in the HttpContext.Current.Request HttpContext.Request或HttpContext.Current.Request URL中是否缺少“#”字母? - '#' letter is missing in HttpContext.Request or HttpContext.Current.Request url? 我可以使用动态重定向HttpContext.Current.Request吗? - can I use dynamic to redirect HttpContext.Current.Request? HttpControllerContext.Request和HttpContext.Current.Request之间的区别 - Difference between HttpControllerContext.Request and HttpContext.Current.Request HttpContext.Current.Request和Page.Request中的Url.Host - Url.Host in HttpContext.Current.Request and Page.Request 我想在我的Windows窗体中包含HttpContext.Current.Request - I want to include HttpContext.Current.Request in my windows forms 什么HttpContext.Current.Request [“ CarName”]!= null,它在做什么? - what HttpContext.Current.Request[“CarName”] != null, what it is doing? HttpContext.Current.Items []和HttpContext.Current.Request []之间有什么区别? - What's the differences between HttpContext.Current.Items[] and HttpContext.Current.Request[]? HttpContext.Current.Request在外部C#类中导致空对象引用 - HttpContext.Current.Request resulting in null object reference in Outer C# class
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM