ASP — Server Object
Server.MapPath
<%
Dim physicalPath
physicalPath = Server.MapPath("/images/photo.jpg")
Response.Write(physicalPath)
%>
Server.Execute
<%
Server.Execute("header.asp")
' Content from header.asp inserted here
%>
Server.Transfer
<%
' Transfer to another page (same request)
Server.Transfer("other.asp")
%>
Server.URLEncode
<%
Dim encoded
encoded = Server.URLEncode("Hello World")
Response.Write(encoded)
%>
Server.HTMLEncode
<%
Dim userInput
userInput = "<script>alert('xss')</script>"
Response.Write(Server.HTMLEncode(userInput))
%>
Server.CreateObject
<%
Set fso = Server.CreateObject("Scripting.FileSystemObject")
Set file = fso.OpenTextFile(Server.MapPath("/data.txt"), 1)
content = file.ReadAll
file.Close
Set file = Nothing
Set fso = Nothing
%>
Methods Summary
| Method | Description |
|---|---|
| MapPath | Physical path |
| Execute | Run page |
| Transfer | Redirect internally |
| URLEncode | URL encode |
| HTMLEncode | HTML encode |
| CreateObject | Create COM object |
Mini Practice
- Map virtual paths
- Execute another page
- Encode output
- Create file object
Up Next
Continue with File System — file operations.
Related Topics
Frequently Asked Questions about Server Object
What is Server Object in ASP?
Server Object is a fundamental concept in ASP. This lesson explains it step by step with clear examples, making it easy for beginners to understand.
How do I learn Server Object?
Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Server Object.
Why is Server Object important in ASP?
Server Object is essential for ASP development. Understanding this concept will help you write better code and solve real-world problems more effectively.