首页 新闻 会员 周边 捐助

问一个技术性的问题

0
悬赏园豆:20 [已解决问题] 解决于 2011-05-20 11:39

我做了一个bs项目,发布出来,但是在iis上面的配置想做个小程序来配置,不知道有哪位高手做过这样的例子,可以知道下,谢谢。

dinoy的主页 dinoy | 初学一级 | 园豆:160
提问于:2011-05-19 19:18
< >
分享
最佳答案
0

在Google中搜索 C#操作IIS 关键字,有很多使用说明,及相关的示例!

 

 

View Code
#region 新建立一个IISWEB站点

///<summary>
///添加一个站点
///</summary>
public string CreateWebSite()
{
int siteID = int.Parse(GetNewWebSiteID());
try
{
root
= new DirectoryEntry("IIS://" + this._server + "/W3SVC");
if (EnsureNewSiteEnavaible(this._serverip + ":" + this._port + ":" + this._domain) || EnsureNewSiteEnavaible(this._server + ":" + this._port + ":" + this._domain))
{
return "该站点已经存在,请重新命名站点!";
}
else
{
DirectoryEntry site
= (DirectoryEntry)root.Invoke("Create", "IIsWebServer", siteID);
site.Invoke(
"Put", "ServerComment", this._webSiteName);
site.Invoke(
"Put", "KeyType", "IIsWebServer");
site.Invoke(
"Put", "ServerBindings", this._serverip + ":" + this._port + ":" + this._domain);
site.Invoke(
"Put", "ServerState", 2);
site.Invoke(
"Put", "FrontPageWeb", 1);
site.Invoke(
"Put", "DefaultDoc", "default.aspx,index.aspx,index.html,index.htm,default.htm,default.html");
site.Invoke(
"Put", "ServerAutoStart", 1);
site.Invoke(
"Put", "ServerSize", 1);
site.Invoke(
"SetInfo");
site.CommitChanges();
root.CommitChanges();

DirectoryEntry siteVDir
= site.Children.Add("Root", "IISWebVirtualDir");
siteVDir.Properties[
"AppIsolated"][0] = 2;
siteVDir.Properties[
"Path"][0] = this._path;
siteVDir.Properties[
"AccessFlags"][0] = 513;
siteVDir.Properties[
"FrontPageWeb"][0] = 1;
siteVDir.Properties[
"AppRoot"][0] = string.Format("/LM/W3SVC/{0}/Root", siteID);
siteVDir.Properties[
"AppFriendlyName"][0] = "默认应用程序";


PropertyValueCollection propValues
= siteVDir.Properties["MimeMap"];
IISOle.MimeMapClass newMimeType
= new IISOle.MimeMapClass();
newMimeType.Extension
= ".flv";
newMimeType.MimeType
= "flv-application/octet-stream";
propValues.Add(newMimeType);

string strerror = @"400,*,FILE,C:\WINDOWS\help\iisHelp\common\400.htm" +
@" 401,1,FILE,C:\WINDOWS\help\iisHelp\common\401-1.htm" +
@" 401,2,FILE,C:\WINDOWS\help\iisHelp\common\401-2.htm" +
@" 401,3,FILE,C:\WINDOWS\help\iisHelp\common\401-3.htm" +
@" 401,4,FILE,C:\WINDOWS\help\iisHelp\common\401-4.htm" +
@" 401,5,FILE,C:\WINDOWS\help\iisHelp\common\401-5.htm" +
@" 401,7,FILE,C:\WINDOWS\help\iisHelp\common\401-1.htm" +
@" 403,1,FILE,C:\WINDOWS\help\iisHelp\common\403-1.htm" +
@" 403,2,FILE,C:\WINDOWS\help\iisHelp\common\403-2.htm" +
@" 403,3,FILE,C:\WINDOWS\help\iisHelp\common\403-3.htm" +
@" 403,4,FILE,C:\WINDOWS\help\iisHelp\common\403-4.htm" +
@" 403,5,FILE,C:\WINDOWS\help\iisHelp\common\403-5.htm" +
@" 403,6,FILE,C:\WINDOWS\help\iisHelp\common\403-6.htm" +
@" 403,7,FILE,C:\WINDOWS\help\iisHelp\common\403-7.htm" +
@" 403,8,FILE,C:\WINDOWS\help\iisHelp\common\403-8.htm" +
@" 403,9,FILE,C:\WINDOWS\help\iisHelp\common\403-9.htm" +
@" 403,10,FILE,C:\WINDOWS\help\iisHelp\common\403-10.htm" +
@" 403,11,FILE,C:\WINDOWS\help\iisHelp\common\403-11.htm" +
@" 403,12,FILE,C:\WINDOWS\help\iisHelp\common\403-12.htm" +
@" 403,13,FILE,C:\WINDOWS\help\iisHelp\common\403-13.htm" +
@" 403,15,FILE,C:\WINDOWS\help\iisHelp\common\403-15.htm" +
@" 403,16,FILE,C:\WINDOWS\help\iisHelp\common\403-16.htm" +
@" 403,17,FILE,C:\WINDOWS\help\iisHelp\common\403-17.htm" +
@" 403,18,FILE,C:\WINDOWS\help\iisHelp\common\403.htm" +
@" 403,19,FILE,C:\WINDOWS\help\iisHelp\common\403.htm" +
@" 403,20,FILE,C:\WINDOWS\help\iisHelp\common\403-20.htm" +
@" 404,*,URL,/404.aspx" +
@" 404,2,FILE,C:\WINDOWS\help\iisHelp\common\404b.htm" +
@" 404,3,FILE,C:\WINDOWS\help\iisHelp\common\404b.htm" +
@" 405,*,FILE,C:\WINDOWS\help\iisHelp\common\405.htm" +
@" 406,*,FILE,C:\WINDOWS\help\iisHelp\common\406.htm" +
@" 407,*,FILE,C:\WINDOWS\help\iisHelp\common\407.htm" +
@" 412,*,FILE,C:\WINDOWS\help\iisHelp\common\412.htm" +
@" 414,*,FILE,C:\WINDOWS\help\iisHelp\common\414.htm" +
@" 415,*,FILE,C:\WINDOWS\help\iisHelp\common\415.htm" +
@" 500,12,FILE,C:\WINDOWS\help\iisHelp\common\500-12.htm" +
@" 500,13,FILE,C:\WINDOWS\help\iisHelp\common\500-13.htm" +
@" 500,15,FILE,C:\WINDOWS\help\iisHelp\common\500-15.htm" +
@" 500,16,FILE,C:\WINDOWS\help\iisHelp\common\500.htm" +
@" 500,17,FILE,C:\WINDOWS\help\iisHelp\common\500.htm" +
@" 500,18,FILE,C:\WINDOWS\help\iisHelp\common\500.htm" +
@" 500,19,FILE,C:\WINDOWS\help\iisHelp\common\500.htm";
string[] strerrorlist = strerror.Split(' ');
siteVDir.Properties[
"HttpErrors"].Value = strerrorlist;

siteVDir.Invoke(
"AppCreate", true);
root.CommitChanges();
siteVDir.CommitChanges();
site.CommitChanges();
return "创建站点成功!";
}
}
catch (Exception ex)
{
return ex.Message;
}
}
#endregion

 

 

收获园豆:20
/aiq浪子飞龙 | 小虾三级 |园豆:1189 | 2011-05-20 11:20
谢谢你的答案,虽说昨天晚上已经解决,但是也是你所说的办法。加分给你。
dinoy | 园豆:160 (初学一级) | 2011-05-20 11:39
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册