Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need UrlHelper inside global.asax

I need to set up a bunch of paths and URLs when my app starts, ie in global.asax. Using UrlHelper.Content() is the easiest way to do that, but it is not available for use.

So how can I get an instance of it inside global.asax? I tried creating one, but of course RequestContext doesn't exist.

The answer most linked-to is here but that throws exceptions for me. I am using the latest MVC3.

like image 461
merom4 Avatar asked Sep 15 '25 04:09

merom4


1 Answers

The code that you have linked to doesn't work for you because you are probably running your application in IIS 7 Integrated Mode (in contrast to Classic Mode). In integrated mode you have no access to the HttpContext in Application_Start. So if on all price you need to generate urls in your Application_Start method forget about UrlHelper, you will need some other method. This being said you could of course use this code in events like Application_BeginRequest, ...

And by the way it's strange that you need to generate urls there. I have never had such need. Maybe you could explain your scenario in more details in order to get a more adapted solution to it.

like image 152
Darin Dimitrov Avatar answered Sep 16 '25 19:09

Darin Dimitrov