views:

190

answers:

2

Here's what I want to do:

My web application is very slow at first until all pages have been precompiled and the cache has been populated. I want to 'warm up' the application in Global.asax by triggering a few HTTP requests to the slowest pages.

The problem is that I don't know which port the application is running on. Could be 80 (my local IIS or the deployed server, 8080 on our test server or some random port for some colleagues who use the ASP.NET development server)

I thought it would be fairly simple to read the merged web configuration, extract the binding, create a url and trigger the request with HttpWebRequest.

However, I had no luck whatsoever... (I mainly tried WebConfigurationManager)

Any ideas?

A: 

If you have access to the Page object (I'm not sure if you do in global.asax since I never use it in my applications) then you can use its ResolveUrl(string path) method to get the correct URL eg

string myurl = Page.ResolveUrl("~/MyPage.aspx");

Where ~/ refers to the root of the ASP.Net application

RobV
I knew about that one, although I think it only gives the absolute path without the scheme, hostname and port, like /MyApplication/MyPath.aspx. But if I had the Page object, Page.Request.Url or Page.Request.RawUrl would be the thing... I am also not sure if Application_Start in Global.asax is the right place, I don't know if it's called when the app is restarted or when the first request comes
chris166
A: 

I think you should be able to get this info from the Request object.

That said, I would be leery about worrying about this without some hard evidence from production that it is in fact a problem.

Wyatt Barnett
No it's not really a problem, and I'm not actively pursuing the issue any longer. But somehow I feel that the web application should be able to figure out its own IIS configuration. Or at least I want a good reason why this is forbidden.
chris166