1

I a trying to test the following code. This is a summarised code.

string url = filterContext.HttpContext.Request.Url.ToString();
if (Url.IsLocalUrl(url))
        {
            return Redirect(url);
        }
        else
        {
            return RedirectToAction("Index", "Home");
        }

In this code the url is obtained from context but in my original code it is passed to the controller action as string from a Authorize filter and looks like http://localhost:53249/Products in Debug.Write. However the IF is not satisfied that the url is local URL can someone explain what I am doing wrong.

3 Answers 3

2

Solved it by using the following sentence

string url = filterContext.HttpContext.Request.Url.PathAndQuery;
Sign up to request clarification or add additional context in comments.

Comments

1

I guess you only need to chek for HttpRequest.IsLocal

Comments

0

Pass the returnUrl to Url.IsLocalUrl() instead of the current request url context. Your passing invalid url to Url.IsLocalUrl().

1 Comment

that sentence is actually in the Filter and not in controller.

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.