1

i have an asp.net-mvc site and one of the pages is

http://www.mysite.com/Report

users can add client side filtering which generates urls like this:

http://www.mysite.com/Report?Region=US

i want to take a link like this:

http://www.mysite.com/MyLastReport

and have a controller action that mimics as if a person added some parameters to the URL like this:

http://www.mysite.com/Report?Region=US

as my server side code uses:

 Request.Params[]

to filter my queries and i want to use the same code path to get the results as if the URL had these parameters on the client side.

also, is there anyway to literally do a redirect of the URL from the server side so i actually change the URL in the browser to:

http://www.mysite.com/Report?Region=US

1 Answer 1

2

Add the following to the Global.asax:

protected void OnBeginRequest(object sender, EventArgs e)
{
    if (Request.Url.AbsolutePath.Equals("/MyLastReport", StringComparison.OrdinalIgnoreCase)) {
        Context.RewritePath("/Report?Region=US");
    }
}

public override void Init()
{
    base.Init();
    BeginRequest += OnBeginRequest;
}

UPDATE: From controller action you can use RedirectToAction method:

RedirectToAction("ReportActionName", new { Region = "US" });
Sign up to request clarification or add additional context in comments.

1 Comment

K. - i want to do this in the controller action as the filter is based on a database query

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.