ASP.NET:获取* *真正的原始网址 [英] ASP.NET: Get *real* raw URL

查看:116
本文介绍了ASP.NET:获取* *真正的原始网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在ASP.NET中,有没有什么办法来获得的真正的原始URL?

In ASP.NET, is there any way to get the real raw URL?

例如,如果用户浏览到http://example.com/mypage.aspx/%2F,我希望能够得到http://example.com/mypage.aspx/% 2F,而不是http://example.com/mypage.aspx//。

For example, if a user browse to "http://example.com/mypage.aspx/%2F", I would like to be able to get "http://example.com/mypage.aspx/%2F" rather than "http://example.com/mypage.aspx//".

我当然会像一个干净的方式做到这一点的,但我可以使用反射或访问晦涩的特性有一个哈克方式生活。

I would of course like a clean way to do it, but I can live with a hacky approach using reflection or accessing obscure properties.

目前,我尝试使用授权头的URI(工作),但我不能依靠它总是在那里。

At the moment, I try to use the uri in the Authorization-header (which works), but I cannot rely on that always being there.

编辑:

我真正想要做的是能与http://example.com/mypage.aspx/%2F和http://example.com/mypage.aspx/%2F%2F区别

What I really want to do is to be able to distinguish between "http://example.com/mypage.aspx/%2F" and "http://example.com/mypage.aspx/%2F%2F".

它看起来像ASP.NET%2F%2F先转换成//,然后斜线转换成一个单一的斜杠。

It looks like ASP.NET first converts "%2F%2F" into "//" and then converts the slashes into a single slash.

所以才重新编码它是行不通的。

So just re-encoding it is not going to work.

推荐答案

以下code为我工作:

The following code works for me:

IServiceProvider serviceProvider = (IServiceProvider)HttpContext.Current;
HttpWorkerRequest workerRequest = (HttpWorkerRequest)serviceProvider.GetService(typeof(HttpWorkerRequest));
string realUrl = workerRequest.GetServerVariable("HTTP_URL");

请注意,在IIS运行它只适用,而不是下F.X. ASP.NET开发服务器!

Note that this only works when running on the IIS and not under f.x. ASP.NET Development Server!

由于<一个href=\"http://stackoverflow.com/questions/757806/get-the-exact-url-the-user-typed-into-the-browser/757813#757813\">Lucero在另一个线程和 Zhaph 答案指着我该线程。

Thanks to Lucero for the answer in another thread and Zhaph for pointing me to the thread.

这篇关于ASP.NET:获取* *真正的原始网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆