[點晴永久免費OA]asp獲取當(dāng)前網(wǎng)址和文件名的代碼
當(dāng)前位置:點晴教程→點晴OA辦公管理信息系統(tǒng)
→『 經(jīng)驗分享&問題答疑 』
Dim curUrl
curUrl = Replace(Request.ServerVariables("script_Name"),"/","")
當(dāng)前頁地址
<%dim urlname urlname=Request.ServerVariables("QUERY_STRING")%> <%=Request.ServerVariables("script_NAME")%><%if urlname<>"" then%>?<%=urlname%><%end if%> 需要用到這個功能,沒怎么測試呢,測試后給具體代碼。
假如地址是: http://dxy.com:8082/test/geturl.asp?Param-VR52tmx3syn03777.html 方法一:簡單,得不到參數(shù),只有一個虛擬路徑,代碼如下: GetUrl =request("url") '這個因為我們沒有url=什么字樣所以直接pass掉 方法二:得到整個URL,得到參數(shù),代碼如下: '得到當(dāng)前頁面的地址 Function GetUrl() On Error Resume Next Dim strTemp If LCase(Request.ServerVariables("HTTPS")) = "off" Then strTemp = "http://" Else strTemp = "https://" End If strTemp = strTemp & Request.ServerVariables("SERVER_NAME") If Request.ServerVariables("SERVER_PORT") <> 80 Then strTemp = strTemp & ":" & Request.ServerVariables("SERVER_PORT") strTemp = strTemp & Request.ServerVariables("URL") If Trim(Request.QueryString) <> "" Then strTemp = strTemp & "?" & Trim(Request.QueryString) GetUrl = strTemp End Function 經(jīng)測試這個代碼得到的路徑為: /test/geturl.asp?Param-VR52tmx3syn03777.html= 方法二:得到虛擬路徑,得到參數(shù),代碼如下: Private Function GetUrl() Dim scriptAddress,M_ItemUrl,M_item scriptAddress = CStr(Request.ServerVariables("script_NAME")) '取得當(dāng)前地址 M_ItemUrl = "" If (Request.QueryString <> "") Then scriptAddress = scriptAddress & "?" For Each M_item In Request.QueryString If M_item = "page_num" Then Exit for '此處的作用就是過濾掉Page_num這個頁次的參數(shù)(該參數(shù)是在page_turn.asp中自行設(shè)置的,根據(jù)個人設(shè)定而變),否則每次翻頁都會疊加這個參數(shù),雖然不影響功能,但總歸不太好吧~~ If InStr(page,M_Item)=0 Then M_ItemUrl = M_ItemUrl & M_Item &"="& Server.URLEncode(Request.QueryString(""&M_Item&"")) else M_ItemUrl = M_ItemUrl & M_Item &"="& Server.URLEncode(Request.QueryString(""&M_Item&"")) & "&" End If Next Else scriptAddress = scriptAddress & "?" end if GetUrl = scriptAddress & M_ItemUrl End Function 上面的代碼得到的地址為: http://dxy.com:8082/test/geturl.asp?Param-VR52tmx3syn03777.html 基本上差不多,如果只是為了得到?號后面的東西,我們可以用下面的代碼: response.write replace(request.querystring,".html","") 得到的就是Param-VR52tmx3syn03777,是不是滿足了我們的需要了呢。 PS:上面的所有情況只是針對純asp,如果結(jié)合urlrewrite的話,功能會有所增強,搜索的友好些,也會加強。 該文章在 2022/6/22 0:31:11 編輯過 |
關(guān)鍵字查詢
相關(guān)文章
正在查詢... |