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

时间:2016-07-01 13:17:48

标签: c# asp.net asp.net-mvc

在我的登录页面上,我有一个returnUrl查询字符串参数,可以在重定向到登录页面之前返回到您想要访问的页面。

即。 http://localhost/login?returnUrl=//testsection/testpage

如果returnUrl有多个斜杠,它将重定向到http://testsection/testpage而不是http://localhost/testsection/testpage

有没有办法我可以把字符串格式化为有效?

1 个答案:

答案 0 :(得分:0)

返回url验证后重定向

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