name of aspx page at runtime

Posted on 2013-10-15
Medium Priority
Last Modified: 2013-10-21
How do I get the name of aspx page at runtime?
Question by:HLRosenberger
  • 3
  • 3
LVL 84

Expert Comment

by:Dave Baldwin
ID: 39574718
Use the SERVER variables.  This short program will display all the server variables available on your web server.
<%@ Page Language = "VBScript" AspCompat="True" %>
<% Response.Buffer = true %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

<title>ASPX .NET Server Variables</title>
<h1 align="center">ASPX .NET Server Variables</h1>
Dim loop1, loop2 As Integer
Dim arr1(), arr2() As String
Dim coll As NameValueCollection

' Load ServerVariable collection into NameValueCollection object.
' Get names of all keys into a string array.
arr1 = coll.AllKeys 
For loop1 = 0 To arr1.GetUpperBound(0)
   Response.Write("<b>" & arr1(loop1) & "</b>: ")
   arr2 = coll.GetValues(loop1) ' Get all values under this key.
   For loop2 = 0 To arr2.GetUpperBound(0)
      Response.Write("Value " & CStr(loop2) & ": " & Server.HtmlEncode(arr2(loop2)) & "<br>")
   Next loop2
Next loop1

Response.Write ("<br>" & vbCrLf)
Response.Write ("REMOTE_ADDR" & ": " _
	& Request.ServerVariables("REMOTE_ADDR") _
	& "<br>" & vbCrLf)



Open in new window

LVL 84

Expert Comment

by:Dave Baldwin
ID: 39574728
Request.ServerVariables("SCRIPT_NAME") or Request.ServerVariables("URL") are the ones you most likely want.

Author Comment

ID: 39574735
Maybe I did not ask correctly.  I want the name of the associated aspx file, where the code that is executing in the VB codebehind.   I seem to remember using Reflection to do this.
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

LVL 84

Expert Comment

by:Dave Baldwin
ID: 39574760
Is this running thru the web server as a web page?  If it is not, then the method I showed you will not work.

Accepted Solution

HLRosenberger earned 0 total points
ID: 39574780
This does the trick.


Author Closing Comment

ID: 39587240
This does the trick.

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
There is a wide range of advantages associated with the use of ASP.NET. This is why this programming framework is used to create excellent enterprise-class websites, technologies, and web applications.
Free Data Recovery software is an advanced solution from Kernel Tools to recover data and files such as documents, emails, database, media and pictures, etc. It supports recovery from physical & logical drive after a hard disk crash, accidental/inte…
Through the video, you can check the migration process of Outlook PST file to PDF. Kernel for Outlook to PDF tool can convert Outlook emails with all attributes like Subject, To, From, Cc, Bcc and other folders such as Inbox, Outbox, Sent Items, Jun…
Suggested Courses

619 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question