dpol

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

ASP.Net管理IIS7

老程序是管理IIS6,服务器更新IIS7后不能使用。

在网上查询到这个地址的介绍http://dflying.cnblogs.com/archive/2006/04/17/377276.html

不过按照上面的代码不能生成。

ServerManager iisManager = new ServerManager();
iisManager.Sites.Add(
"NewSite""http""*:8080:""d:\\MySite");
iisManager.Update(); 

 

显示没有 Update方法。

 

经过查询MSDN,找到解决办法,调试成功。

 

复制代码
        /// <summary>
        
/// IIS7创建网站
        
/// </summary>
        
/// <param name="name">网站名称</param>
        
/// <param name="Port">端口</param>
        
/// <param name="domain">绑定域名</param>
        public void CreateSiteByName(string name, string Port, string domain)
        {
            
string path = @"C:\web\" + name + "site";

            
// Validate the site name
            char[] invalid = SiteCollection.InvalidSiteNameCharacters();
            
if (name.IndexOfAny(invalid) > -1)
            {
                Console.WriteLine(
"Invalid site name: {0}", name);
            }

            
// Create the content directory if it doesn't exist.
            if (!System.IO.Directory.Exists(path))
            {
                System.IO.Directory.CreateDirectory(path);
            }

            
// Create a new site using the new directory and update the config
            ServerManager manager = new ServerManager();
            
try
            {   
// Add this site.

                Site hrSite 
= manager.Sites.Add(name, "http""*:" + Port + ":" + domain, path);
                hrSite.ServerAutoStart 
= true;
                manager.CommitChanges();
                Console.WriteLine(
"Site " + name + " added to ApplicationHost.config file.");
            }
            
catch
            {
            }
        }
复制代码

 

 

 

 程序发布的时候显示有没权限。需要给C:\Windows\System32\inetsrv\config添加network service用户权限才行。 

posted on   dpol  阅读(526)  评论(3编辑  收藏  举报

编辑推荐:
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
点击右上角即可分享
微信分享提示