简体   繁体   English

如何将字符串格式化为正确的URL

[英]How to format a string to a proper url

On my login page I have a returnUrl query string parameter to bring you back to the page you wanted to visit before you were redirected to the login page. 在我的登录页面上,我有一个returnUrl查询字符串参数,可以在重定向到登录页面之前返回到您要访问的页面。

Ie http://localhost/login?returnUrl=//testsection/testpage http:// localhost / login?returnUrl = // testsection / testpage

If the returnUrl has multiple slashes it will redirect to http://testsection/testpage instead of http://localhost/testsection/testpage 如果returnUrl有多个斜杠,它将重定向到http:// testsection / testpage而不是http:// localhost / testsection / testpage

Is there a way I can take a string and format it to be valid? 有没有办法我可以把字符串格式化为有效?

返回url验证重定向后

Response.Redirect("http://" + (HttpContext.Current.Request.Url.Host + Request["returnUrl"]).Replace("//","/"));

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM