1

ASP.Net MVC has some really nice features for making sure that you have the correct URL for the route you want. So I can use the HtmlHelper class you get the correct URL for my views:-

@Html.RouteLink("Link Text", new {controller = "articles", action = "tag"})

Now this is great. However, I find myself in the situation that I want to know the URL but I am not writing it into a view. So my question is what is the best way to get this information in the controller? I have read various posts that show you how to sneakily create an instance of HtmlHelper but there must be a more straightforward way of doing this.

Thanks.

2 Answers 2

2

You can try the UrlHelper.RouteUrl. UrlHelper is accessible via the Url property on controller.

Sign up to request clarification or add additional context in comments.

Comments

0

Controller has access to all information about the request, so Request object is where you can find the Url

Request.Url.ToString()

Comments

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.