在ASP.NET中,有没有办法获得真正的原始URL?
例如,如果用户浏览到" http://example.com/mypage.aspx/%2F ",我希望能够获得" http://example.com/mypage.aspx/%2F "比" http://example.com/mypage.aspx// ".
我当然喜欢干净的方式,但我可以使用反射或访问模糊属性的hacky方法.
目前,我尝试在Authorization-header(可行)中使用uri,但我不能依赖于那里总是存在的.
编辑:
我真正想要做的是能够区分" http://example.com/mypage.aspx/%2F "和" http://example.com/mypage.aspx/%2F%2F ".
看起来ASP.NET首先将"%2F%2F"转换为"//",然后将斜杠转换为单个斜杠.
所以只是重新编码它是行不通的.
我使用用户用Rawurlencode()编码的令牌发送有关用户激活的html电子邮件。
所以-链接显示在电子邮件中,如下所示:
<a href="http://site.com/auth?action=confirmActivation&user=79&token=zlKoFo%22f%27g%3FtUb%27%29Z~L1%25zKh%5EG%23_Aj%5Ckbbbd4fdb9121b50f643f12c937ab1c03d5f09861" target="_blank">Click here to activate your account</a>
Run Code Online (Sandbox Code Playgroud)
但是,当我单击此链接时,我的页面网址看起来像这样:
http://site.com/auth?action=confirmActivation&user=79&token=zlKoFo%22f%27g%3FtUb%27%29Z~L1%25zKh^G%23_Aj%5Ckbbbd4fdb9121b50f643f12c937ab1c03d5f09861
Run Code Online (Sandbox Code Playgroud)
所以-之前的令牌(这是它在我的电子邮件中的显示方式):
zlKoFo%22f%27g%3FtUb%27%29Z~L1%25zKh%5EG%23_Aj%5Ckbbbd4fdb9121b50f643f12c937ab1c03d5f09861
Run Code Online (Sandbox Code Playgroud)
之后的令牌:
zlKoFo%22f%27g%3FtUb%27%29Z~L1%25zKh^G%23_Aj%5Ckbbbd4fdb9121b50f643f12c937ab1c03d5f09861
Run Code Online (Sandbox Code Playgroud)
看起来我的浏览器单击时会自动进行一些转换吗?为什么?
我正在尝试由多字字符串构成一个URL:
$str = "my string"
Run Code Online (Sandbox Code Playgroud)
而我试图得到:
"http mysite.com/search/my%20string"
Run Code Online (Sandbox Code Playgroud)
但我无法使用PHP做到这一点。
urlencode($str) => "my+string"
rawurlencode($str)=>"my string"
Run Code Online (Sandbox Code Playgroud)
我怎么能得到"my%20string"
?
谢谢你的帮助 !
也许我可以做,str_replace(urlencode(),etc);
但是urlencode是否有一个参数,这样它本身就可以正确转换?
事实证明,正如Amal Murali所说的那样,rawurlencode()
确实如此,当我将鼠标悬停在链接上时,在浏览器中看不到它。
但是,当我检查源代码或单击链接时,会看到rawurlencode();
生成正确的链接。(带有%20
。)。