ASP.NET: Get *real* raw URL

2019-04-07 12:44发布

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

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.

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

EDIT:

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".

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.

8条回答
一夜七次
2楼-- · 2019-04-07 13:14
 Server.HtmlEncode(Request.RawUrl);

The raw URL is defined as the part of the URL following the domain information. In the URL string http://www.contoso.com/articles/recent.aspx, the raw URL is /articles/recent.aspx. The raw URL includes the query string, if present.

see also:link text

查看更多
ら.Afraid
3楼-- · 2019-04-07 13:15

Get the url from the request and urlencode only the query string part and then concatenate them

查看更多
登录 后发表回答