IIS 更新ScriptMaps
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("<BR>Add: " & Mapping(ext, MappingAction.Add))
‘’ Update extension to be processed by latest ASPX script processor
Response.Write("<BR>Update: " & Mapping(ext, MappingAction.Update))
‘’ Setup extension so that it is not processed by any script processor
Response.Write("<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
下一篇:SQL注入天书—ASP注入漏洞全接触 >>
相关文章:
- · 用javascript调用webservice(webservice behavior)
- · asp.net无法调试的解决方法
- · 奇特的用法:把列名取到一个字符串中
- · ASP.NET编程习惯
- · ASP.Net 1.x 中 __doPostBack实现的问题
- · 在Remoting Server上取得Remoting Client的IP地址
- · ASP 写的自动生成SELECT 表单的函数
- · ASP 写的判断 Money 各个位值的函数
- · 如何保存一个字符串Cookie,在其它WebForm中可以访问到?
- · 几个开源项目配置信息的存储和处理的方式
- · [ASP-Last-Code]显示ASP页面的代码
- · C#实现WEB服务器
- · 一个完整的案例
- · 自定义DataGrid分页设置
- · 虚拟主机如何提高整体性能-application的使用
- · 我的DataGrid嵌套DataList(未解决)
- · 大文件上传研究
- · IIS属性大全
- · 在Asp程序中取得表单所有内容的方法
- · 发布攻击台湾国旗设计网的ASP代码
- · ADO.NET 2.0 Feature Matrix
- · asp.net中的模态对话框
- · ASP.net中动态加载控件时一些问题的总结
- · 一切都因为分页-再谈分页
- · 简单快捷实现ASP在线发邮件功能
- · 改进性能和样式的 25+ ASP 技巧
- · 我的asp之路
- · 网上考试系统的一点心得
- · asp程序错误详细说明例表
- · 用好活动字幕标记—marquee
- · asp.net实现分组全选部分复选框
- · 在PPC上编译ASP,吃惊!!!
- · Asp之Request对象(1)
- · 汉字转拼音
- · 在ASP文件中调用DLL
- · 存储过程介绍及asp存储过程的使用
- · 如何把ASP编写成DLL
- · Asp.Net下导出/导入规则的Excel(.xls)文件
