简体   繁体   English

在IIS中自动验证网站

[英]Automate verifying website in IIS

As a part of build output for a ASP.NET website project we create a bin folder. 作为ASP.NET网站项目的生成输出的一部分,我们创建一个bin文件夹。 In order to validate that the build output is actually a functional website we load it into the IIS. 为了验证构建输出实际上是一个可正常运行的网站,我们将其加载到IIS中。 And, the browse to it. 并且,浏览到它。

Is there a way to automate this in C# ? 有没有办法在C#中自动执行此操作?

I am not looking for a test framework to do this. 我不是在寻找测试框架来做到这一点。 Just a simple C# light-weight application that can point IIS to this bin folder, test the web application loads thats all. 只需一个简单的C#轻量级应用程序即可将IIS指向该bin文件夹,然后测试Web应用程序是否加载了所有内容。

Make your IIS VirtualDirectory/Application point to your bin folder, or a drop folder that you copy all the bin folders content when you do a Build. 使您的IIS VirtualDirectory / Application指向您的bin文件夹,或指向在构建时复制所有bin文件夹内容的放置文件夹。

Then do an IISReset: 然后执行IISReset:

System.Diagnostics.Process.Start("C:\Windows\System32\iisreset.exe");

Then hit the website using a Webclient: 然后使用Webclient访问该网站:

WebClient client = new WebClient ();
client.Headers.Add ("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)"); 
Stream data = client.OpenRead (webUrl);
StreamReader reader = new StreamReader (data); 
string s = reader.ReadToEnd (); 
Console.WriteLine (s); 
data.Close (); 
reader.Close ();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM