惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

F
Fortinet All Blogs
Attack and Defense Labs
Attack and Defense Labs
V2EX - 技术
V2EX - 技术
O
OpenAI News
S
Secure Thoughts
H
Heimdal Security Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Schneier on Security
Schneier on Security
H
Hacker News: Front Page
S
Security Affairs
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Vercel News
Vercel News
Microsoft Security Blog
Microsoft Security Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
P
Proofpoint News Feed
The Register - Security
The Register - Security
GbyAI
GbyAI
Cloudbric
Cloudbric
MongoDB | Blog
MongoDB | Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
K
Kaspersky official blog
Forbes - Security
Forbes - Security
Y
Y Combinator Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
Scott Helme
Scott Helme
Hacker News - Newest:
Hacker News - Newest: "LLM"
The Cloudflare Blog
Recorded Future
Recorded Future
人人都是产品经理
人人都是产品经理
Cyberwarzone
Cyberwarzone
C
CERT Recently Published Vulnerability Notes
Webroot Blog
Webroot Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
L
LangChain Blog
T
Tor Project blog
Microsoft Azure Blog
Microsoft Azure Blog
博客园_首页
Hacker News: Ask HN
Hacker News: Ask HN
Blog — PlanetScale
Blog — PlanetScale
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
B
Blog RSS Feed
N
News and Events Feed by Topic
阮一峰的网络日志
阮一峰的网络日志
I
Intezer
V
V2EX
T
Tailwind CSS Blog
SecWiki News
SecWiki News
NISL@THU
NISL@THU
C
Check Point Blog

博客园 - From Ocean

how to solve error when start Hyper-V quick create app error log4j 2使用properties文件进行配置 (转载)Tips on using log4net RollingFileAppender by Rohit Gupta (DP)降低代码重构的风险(转载) (Life)牛人的学习方法(转译文) (WPF)WPF事件要点-WPF宝典笔记 (WPF)路由事件要点-WPF宝典笔记 (WPF)依赖属性要点-WPF宝典笔记 (Ruby)Ubuntu12.04安装Rails环境 (Ruby)方法的一些有趣的地方--待补充 (Ruby)Ruby中区块用的一些潜藏关键字 (Ruby)类变量,实例变量,类常量,如何访问变量 (WPF)WPF要点之命令-深入浅出WPF笔记 (WPF)WPF要点之事件-深入浅出WPF笔记 (Algorithm)计算机科学中最重要的32个算法_转载infoq上的文章 (转载)postgresql无法远程登录(设置远程登陆的三点注意事项) (.Net,DevExpress)关于devexpress部分aspx控件需要注意的细节_持续补充ing (.Net,DevExpress)devexpress源码编译需要注意的地方 (Silverlight,WCF,Socket,Cocurrency)一周浏览碰到不错的文章
(Asp.Net)转载-用Powershell 建立IIS web site
From Ocean · 2012-12-05 · via 博客园 - From Ocean

受到continuous delivery 觀念的灌輸,新的專案都盡量朝向能自動化的建置及部署

因為目前使用TFS 2010 ,專案都是web system,這部分倒是網路上有不少文章可以參考,還算容易建立

只是完成專案的部分之後,接下來就會去想如何讓系統的環境也能自動化的建立,首先想解決的就是IIS的設定

一般來說,我想應該跟大家的作法差不多,就是會有一份文件,描述當要新建系統時,要如何設定IIS。當要轉換環境或是要建立一個新的測試環境時,就照著這份文件完成

當然會遇到的問題也應該多數人差不多

1. 文件未更新,實際環境與文件記錄不相同

2.人為設定可能出錯或遺漏,出問題時又要逐步檢查

因此 讓設定IIS的動作自動化,將這自動建置script本身就視為是一份文件

在說明之前,我的環境是windows server 2008 R2,打算在預設web site (default web site) 下建立一個應用程式,程式碼存放路徑d:\Webapp\MyWeb

1. 建立存放code的 folder

01 #將code存放在d:\WebApp\MyWebSite,並判斷folder是否存在
02    #設定給network service 權限
03     
04    $folderPath = "d:\WebApp\MyWeb"
05    $existPath = Test-Path $folderPath
06     
07    if($existPath -eq $false) {
08        New-Item $folderPath -ItemType Directory
09     
10        $acl = Get-Acl $folderPath
11        $ar = New-Object System.Security.AccessControl.FileSystemAccessRule("network service", "FullControl","ContainerInherit, ObjectInherit", "None",  "Allow")
12        $acl.SetAccessRule($ar)
13        Set-Acl $acl -path $folderpath 
14    }

2. 建立Application Pool

01    $appPoolName = "My AppPool"
02    $app = "iis:\AppPools\" + $appPoolName
03    $existAppPool = Test-Path $app
04     
05    if($existAppPool -eq $false) {
06        $appPool = New-Item $appPoolName
07     
08        #Identity --> Network service
09        $appPool.ProcessModel.IdentityType = 2
10     
11        #.net 4
12        $appPool.managedRuntimeVersion = "v4.0"
13     
14        #PopelineMode
15        $appPool.ManagedPipelineMode = 0
16     
17        #start mode
18        $appPool.startMode="AlwaysRunning"
19     
20     
21        #save property
22        $appPool | Set-Item
23    }

這邊要說明一下,這裡用到WebAdministration 模組,因此上述的script執行前,要先import-module WebAdministration

可以參考一下保哥的文章 如何才能在 IIS 7.5 使用 Windows PowerShell Snap-In 功能

$appPool.ProcessModel.IdentityType = 2 指的是Identity用network service,其他意義如下

0 >  Local Service

1 >  Local System

2 > Network Service

3 > User

4 > ApplicationPoolIdentity

$appPool.managedRuntimeVersion = "v4.0" 指用.net framework 4.0

$appPool.ManagedPipelineMode = 0 指是用 Integrated pipeline mode,1則是class pipeline mode

有些設定的調整,因為沒用到就沒列出來

3. 建立application同樣的語法套用,也可以建立web site

01    $appSitePath = "iis:\sites\Default Web Site\MyWebSite"
02    $existWeb = Test-Path $appSitePath
03     
04    if($existWeb -eq $false) {
05        $folderPath = $folderPath = "d:\WebApp\MyWeb"
06        $appPoolName = "My AppPool"
07     
08        New-Item $appSitePath -physicalpath $folderPath -type Application
09     
10        #設定剛剛建立的application pool
11        Set-ItemProperty $appSitePath -name applicationpool -value $appPoolName
12         
13        $appSiteShortName = $appSitePath.ToLower().Replace("iis:\sites\", "").Replace("\", "/")
14     
15        #開啟window authentication
16        Set-WebConfigurationProperty -filter /system.webServer/security/authentication/windowsAuthentication -name enabled -value true -PSPath IIS:\ -location $appSiteShortName
17     
18        #關閉anonymous authentication
19        Set-WebConfigurationProperty -filter /system.webServer/security/authentication/anonymousAuthentication -name enabled -value false -PSPath IIS:\ -location $appSiteShortName
20     
21        #移除預設的首頁並重新設定
22        Remove-WebConfigurationproperty -filter /system.webserver/defaultdocument -name files -PSPath IIS:\ -location $appSiteShortName
23        Add-WebConfiguration -filter /system.webserver/defaultdocument/files -atIndex 0 -value @{value = "default.aspx"} -PSPath IIS:\ -location $appSiteShortName
24    }

將上述分開的script 整理重構成一份powershell檔案即可成為一份自動化建置IIS  web site 的文件

原文链接:http://www.dotblogs.com.tw/maev85/archive/2012/01/18/66433.aspx