分享
 
 
 

IIS 更新ScriptMaps

王朝asp·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

A zip file with your code and stylesheet is also available for download. Make sure you right click on the link and choose Save Target As...

To use the colored code in your pages link to the stylesheet colorcode.css and copy everything between the <pre class='coloredcode'>...</pre> tags. Feel free to modify color assignment in the stylesheet as you wish.

//**************************************

// for :Dynamic ScriptMapping with Metabase

//**************************************

Copyright (c) 2003, Lewis Moten. All rights reserved.

//**************************************

// Name: Dynamic ScriptMapping with Metabase

// Description:Allows you to assign almost any extension to be processed by the ASPX script processor. You may add, update, and remove the extension progromatically without opening the IIS Manager. Great for those of you who do not have access to the machines desktop (such as hosted at other ISPs).

// By: Lewis E. Moten III

//

//

// Inputs:None

//

// Returns:None

//

//Assumes:None

//

//Side Effects:None

//This code is copyrighted and has limited warranties.

//Please see http://www.Planet-Source-Code.com/xq/ASP/txtCodeId.1586/lngWId.10/qx/vb/scripts/ShowCode.htm

//for details.

//**************************************

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim ext As String = "GIF"

' Setup extension to be processed by ASPX script processor

Response.Write("&lt;BR>Add: " & Mapping(ext, MappingAction.Add))

' Update extension to be processed by latest ASPX script processor

Response.Write("&lt;BR>Update: " & Mapping(ext, MappingAction.Update))

' Setup extension so that it is not processed by any script processor

Response.Write("&lt;BR>Delete: " & Mapping(ext, MappingAction.Delete))

End Sub

Enum MappingAction

Add

Update

Delete

End Enum

Private Function Mapping(ByVal ext As String, ByVal action As MappingAction) As Boolean

' Assigns the ASPX processor to the extension specified.

' See IIS documentation for information regarding script mapping

' http://localhost/iishelp/iis/htm/asp/apro9tkj.htm

' Example of Script Mapping:

' ".gif,C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG"

Dim APPL_MD_PATH As String

Dim AppPath As String

Dim App As DirectoryEntry

Dim ScriptMaps As ArrayList

Dim ExtentionExists As Boolean = False

Dim ScriptProcessor As String = ""

Dim Flags As String = "5"

Dim IncludedVerbs As String = "GET,POST,HEAD"

Dim NewMap As String = "{0},{1},{2},{3}"

' Make sure ext is prefixed with "."

If Not ext.IndexOf(".") = 0 Then ext = "." & ext

' Make sure ext is lowercase

ext = ext.ToLower

' Do our best to prevent problems with default script processors

Dim BadExt As String

BadExt = ".asa.asax.ascx.ashx.asmx.asp.aspx.asd.cdx.cer.config."

BadExt &= "cs.csproj.idc.java.jsl.licx.rem.resources.resx.shtm."

BadExt &= "shtml.soap.stm.vb.vbproj.vjsproj.vsdisco.webinfo."

If Not BadExt.IndexOf(ext & ".") = -1 Then

Return False

End If

Response.Write("got here!")

Response.End()

' Get application metadata path

APPL_MD_PATH = Request.ServerVariables("APPL_MD_PATH").ToString

' Format path for ADSI

AppPath = Replace(APPL_MD_PATH, "/LM/", "IIS://localhost/")

' Attempt to acquire the object

Try

If DirectoryEntry.Exists(AppPath) Then

App = New DirectoryEntry(AppPath)

End If

Catch ex As Exception

Return False

End Try

' Get a list of all script mappings

ScriptMaps = New ArrayList(CType(App.Properties("ScriptMaps").Value, Object()))

' If we are not deleting a script map

If Not action = MappingAction.Delete Then

' We need to get the latest processor installed

' that handles aspx pages.

For Each Map As String In ScriptMaps

' if the first value of the string is an ASPX page

If Split(Map, ",", 4)(0) = ".aspx" Then

' The latest script processor is the second

' value in the comma delimited string

ScriptProcessor = Split(Map, ",", 4)(1)

Exit For

End If

Next

' Processor not found!

If ScriptProcessor = "" Then

App.Dispose()

App = Nothing

Return False

End If

End If

' Find out if extension exists

For index As Integer = 0 To ScriptMaps.Count() - 1

' get current map

Dim map As String = ScriptMaps(index).ToString

' if we found the extension

If Split(Map, ",", 4)(0) = ext Then

' Determine results based on action

If action = MappingAction.Add Then

' impossible to add if it exists

App.Dispose()

App = Nothing

Return False

ElseIf action = MappingAction.Update Then

' update the map with latest script processor

ScriptMaps(index) = NewMap.Format(NewMap, ext, ScriptProcessor, Flags, IncludedVerbs)

Exit For

ElseIf action = MappingAction.Delete Then

' delete the map

ScriptMaps.RemoveAt(index)

Exit For

End If

End If

Next

' Is user attempting to add map?

If action = MappingAction.Add Then

' Build the new map

ScriptMaps.Add(NewMap.Format(NewMap, ext, ScriptProcessor, Flags, IncludedVerbs))

End If

' Save the new set of script maps

App.Properties("ScriptMaps").Value = ScriptMaps.ToArray

App.CommitChanges()

App.Dispose()

App = Nothing

Return True

End Function

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有