10

I need to generate a correct URL to a action in my ASP.NET MVC 3 website and this have to be done in the Application_Start in Gloabl.asax.

I have tried to set a UrlHelper but the HttpContext.Current is always null?

The adress i look for is somthing like this : http://www.mysite.se/MyController/MyAction.

I have also tried VirtualPathUtility.ToAbsolute("~/") but that will only give me "/mysite/"

0

1 Answer 1

16

I'm afraid you can't access the HttpContext in the Application_Start when the application is running in the IIS integration mode (you can achieve that in the classic mode but that's not recommended).

Mike describes here a workaround how to do that in Application_BeginRequest such that your code still runs only for the first request not for the later ones.

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

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.