Asp.net mvc 将我的页面重定向到存储为会话变量的页面URL

Asp.net mvc 将我的页面重定向到存储为会话变量的页面URL,asp.net-mvc,asp.net-mvc-3,Asp.net Mvc,Asp.net Mvc 3,我在一页上有以下内容: @{ Session["CurrentUrl"] = Request.Url.ToString(); } 然后我调用另一个页面,在该页面的action方法中,我尝试使用以下命令返回到原始页面 return Session["CurrentUrl"] == null ? Index() : Redirect(Session["CurrentUrl"]); 该方法看起来不错,但当我尝试实现该方法时,我收到了以下错误消息: Error 51 The b

我在一页上有以下内容:

@{ Session["CurrentUrl"] = Request.Url.ToString(); }
然后我调用另一个页面,在该页面的action方法中,我尝试使用以下命令返回到原始页面

return Session["CurrentUrl"] == null ?
    Index() :
    Redirect(Session["CurrentUrl"]);
该方法看起来不错,但当我尝试实现该方法时,我收到了以下错误消息:

Error   51  The best overloaded method match for 'System.Web.Mvc.Controller.Redirect(string)' has some invalid arguments    
"Error  52  Argument 1: cannot convert from 'object' to 'string') 

谁能告诉我这里出了什么问题吗。我不确定如何修复此错误。

您需要将
会话[“CurrentUrl”]
转换为
字符串,因为该方法需要一个字符串

return Session["CurrentUrl"] == null ?
    Index() :
    Redirect((string)Session["CurrentUrl"]);