沈阳市和平慧学网登录:asp怎样取得这个东西

来源:百度文库 编辑:杭州交通信息网 时间:2024/05/02 16:05:42
以第一个问题为主剩下2个愿意的话顺便回答下把
不愿意就算了

1.怎样取得当前网站的网址
(到com/net/org/cn...结尾)
然后存到一个变量UrlSrt里面

--------------------------------------------
2.还有asp里面有没有类似pascal里case of的语句?
(就等于很多个if..else。不过写起来方便点的多个选择语句)

3.从外部读取的一个字符串str,怕被代码注入,怎么处理呢?
多谢ikite
我试试去
上次那个问题如果XXX是a.a可以正常取得么?

1.
<%
Dim UrlStr
UrlStr = "http://" & Request.ServerVariables("SERVER_NAME")

Response.Write UrlStr '输出
%>

2.
If A = 1 Then
Response.Write "1"
ElseIf A = 2 Then
Response.Write "2"
.....
End If
同:
Select Case A
Case 1
Response.Write "1"
Case 2
Response.Write "2"
....
Case Else
....
End Select

3.
<%
Dim Str
Str = Request("str")
Str = Replace(Str,"'","’")

%>

'===============取得当前程序脚本路径==================
Function GetScriptName()
ScriptAddress = CStr(Request.ServerVariables("SCRIPT_NAME"))'取得当前地址
If (Request.QueryString <> "") Then
ScriptAddress = ScriptAddress & "?" & Server.HTMLEncode(Request.QueryString)'取得带参数地址
End If
If Len(ScriptAddress)>250 Then ScriptAddress = Left(ScirptAddress,250)&"..." '进行路径截取,最大为250个字符
GetScriptName = ScriptAddress
End Function
'===========返回带参数的Url,多关键字排序时使用==============
' RemoveList 参数:需要从Url中去除的参数,可以是多个,中间请用逗号隔开
Function KeepUrlStr(RemoveList)
ScriptAddress = CStr(Request.ServerVariables("SCRIPT_NAME"))&"?"'取得当前地址,并加入“?”符号
M_ItemUrl = ""
For Each M_item In Request.QueryString
If InStr(RemoveList,M_Item)=0 Then
M_ItemUrl = M_ItemUrl & M_Item &"="& Server.URLEncode(Request.QueryString(""&M_Item&"")) & "&"
End If
Next
KeepUrlStr = ScriptAddress & M_ItemUrl
End Function
'========取得带端口的URL,推荐使用================
Function Get_ScriptNameUrl()
If request.servervariables("SERVER_PORT")="80" Then
Get_ScriptNameUrl="http://" & request.servervariables("server_name")&lcase(request.servervariables("script_name"))
Else
Get_ScriptNameUrl="http://" & request.servervariables("server_name")&":"&request.servervariables("SERVER_PORT")&lcase(request.servervariables("script_name"))
End If
End Function

'=================用正则表达式突出显示字符串中查询到的单词的函数======================
Function BoldWord(strContent,word)
If word="" Then
BoldWord = strContent
Exit Function
End IF
dim objRegExp
Set objRegExp=new RegExp
objRegExp.IgnoreCase =true
objRegExp.Global=True

objRegExp.Pattern="(" & word & ")"
strContent=objRegExp.Replace(strContent,"<font color=""#FF0000""><b>$1</b></font>" )

Set objRegExp=Nothing
BoldWord=strContent
End Function

'===============取得用户当前IP地址===================
Function GetIP()
uIP = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
If uIP = "" Then uIP = Request.ServerVariables("REMOTE_ADDR")
GetIp = uIP
End Function

Function clerbr(word)
clerbr = replace(word,"<BR>",chr(10)&chr(13))
End Function