【发布时间】:2012-05-19 19:42:51
【问题描述】:
我正在使用 asp.net mvc3 并且有一个问题,我想将用户重定向到用户输入的任何动态链接,如何做到这一点,我目前的工作正在跟进
我尝试了两种类型
1.
控制器
if (condition == true)
{
string Link ="www.google.com"; // suppose this is the url entered by user
ViewData["link"] = Link;
return PartialView("REdirectToLink");
}
REdirectToLink.cshtml
@{
string link = ViewData["link"].ToString();
}
<script type="text/javascript" >
var tlink = "@link";
window.location.replace(tlink);
</script>
2.
控制器
if (condition == true)
{
string Link ="www.google.com"; // suppose this is the url entered by user
return RedirectPermanent(Link);// also tried return Redirect(Link);
}
如何做到这一点,在此先感谢!
【问题讨论】:
-
您遇到了什么问题?重定向不起作用,还是您在询问是否有更好的方法来做到这一点?如果是后者,我认为您的第二种解决方案优于第一种。
-
假设我当前的位置是 "example.com/foo" ,现在当我调用 Redirect 时,它会输入这样的 url "example.com/www.google.com"
标签: c# asp.net-mvc asp.net-mvc-3 c#-4.0