Read IIS7 configuration from within web application?

眉间皱痕 提交于 2019-12-13 18:17:46

问题


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?


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/897461/read-iis7-configuration-from-within-web-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!