<p>I am using an authentication attribute on some of my actions in an asp.net mvc page to refer people to a login screen if they have not authenticated.  My problem is returning them to the referring page after they have logged in.  I was just keeping track of the referring action and referring controller but that becomes problematic when I also need to keep track of some parameters.  Is there some nifty built in trick about which I don't know?</p>

What I did to achieve that result might be overdoing it, and I'd like to see some other methods as well. However, here's my code.
Please note it's using Moq to mock a context... And, I haven't done anything with the querystring yet (my routes don't contain any querystrings).
```
```
var urlReferrer = Request.UrlReferrer;
if (urlReferrer != null)
{
    var url = "~" + Server.UrlDecode(urlReferrer.PathAndQuery);

    // get routecollection
    var routeCollection = new RouteCollection();
    GlobalApplication.RegisterRoutes(routeCollection);

    // mcok context
    var context = new Mock<HttpContextBase>();
    var request = new Mock<HttpRequestBase>();
    context.Expect(ctx => ctx.Request).Returns(request.Object);

    // mock request
    // TODO: convert querystring to namevaluecollection
    // now it's just stripped
    if (url.IndexOf('?') > 0)
    {
        url = url.Substring(0, url.IndexOf('?'));
    }

    var mock = Mock.Get(context.Object.Request);

    // TODO: insert namevaluecollection of querystring
    mock.Expect(req => req.QueryString).Returns(new NameValueCollection());
    mock.Expect(req => req.AppRelativeCurrentExecutionFilePath).Returns(url);
    mock.Expect(req => req.PathInfo).Returns(string.Empty); 

    // get routedata with mocked context
    var routeData = routeCollection.GetRouteData(context.Object);
    var values = routeData.Values;

    return RedirectToAction(routeData.Values["action"].ToString(), values);
}
```
```
As I said, it's maybe a bit overcomplicated :)