从Web应用程序中读取IIS7配置?

时间:2021-08-24 15:16:44

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.

我的Web应用程序一开始非常慢,直到所有页面都已预编译并且已填充缓存。我想通过触发对最慢页面的一些HTTP请求来“预热”Global.asax中的应用程序。

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)

问题是我不知道运行应用程序的端口。可能是80(我的本地IIS或部署的服务器,我们的测试服务器上的8080或一些使用ASP.NET开发服务器的同事的随机端口)

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.

我认为阅读合并的Web配置,提取绑定,创建URL并使用HttpWebRequest触发请求会相当简单。

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

但是,我没有运气......(我主要试过WebConfigurationManager)

Any ideas?

2 个解决方案

#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

如果您有权访问Page对象(我不确定您是否在global.asax中进行操作,因为我从未在我的应用程序中使用它),那么您可以使用其ResolveUrl(字符串路径)方法来获取正确的URL,例如

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

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

其中〜/指的是ASP.Net应用程序的根目录

#2


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

我认为您应该能够从Request对象获取此信息。

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

也就是说,如果没有生产中的一些确凿证据表明这实际上是一个问题,我会担心会担心这一点。

#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

如果您有权访问Page对象(我不确定您是否在global.asax中进行操作,因为我从未在我的应用程序中使用它),那么您可以使用其ResolveUrl(字符串路径)方法来获取正确的URL,例如

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

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

其中〜/指的是ASP.Net应用程序的根目录

#2


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

我认为您应该能够从Request对象获取此信息。

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

也就是说,如果没有生产中的一些确凿证据表明这实际上是一个问题,我会担心会担心这一点。