开发者

implement returnurl in asp.net mvc [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Cl开发者_JAVA百科osed 11 years ago.

How to implement returnurl in asp.net mvc?


Your question is very unclear so I can only be guessing. Personally I pass returnUrl as parameter to actions that need to redirect:

[HttpPost]
public ActionResult Foo(string returnUrl)
{
    // TODO: some processing ...

    // TODO: sanitize the url ensuring that it belongs to the same domain
    return Redirect(returnUrl);
}

and then I build HTML forms to invoke the action and pass the return url:

@using (Html.BeginForm())
{
    @Html.Hidden("returnUrl", Url.Action("someaction", "somecontroller"))
    <input type="submit" value="OK" />
}


We did something like this in one of our projects.

In your controller, add a parameter for the returnUrl then in your method just redirect to it.

public ActionResult SomeActionMethod(int id, string returnUrl)
{
    //do some stuff

    if (!string.IsNullOrWhiteSpace(returnUrl))
    {
        return Redirect(returnUrl);
    }
    else
    {
        //return whatever
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜