Retrieve Page Name in asp.net page

  • Thread starter Thread starter Ersin Inan
  • Start date Start date
E

Ersin Inan

Hi All,
Is there a way to get page name in asp.net code behind? I use this to log
error messages in DB ( and in which page the error occured )
For instance , if it is welcome.aspx , then in C# code , I want to get this
page name to store in DB ( There is a way with Request object , but I want
to retrieve the name in another way )

Any help is appreciated :)

Regards
Ersin
 
Page.GetType().Name will return "YourPageName_aspx". You could replace the
underscore with a dot, which would probably solve your problem. Not sure
how this is any better than using Request.Path though, which I think is
better, as it'll give you the full path to page which errored, making things
easier to debug.

Just my two cents... :-)

Mun
 
Request.ServerVariables still works in ASP.NET like it
did in ASP.

Try this... It will list all of the server variables for
you.

Keith

[Visual Basic]
Dim loop1, loop2 As Integer
Dim arr1(), arr2() As String
Dim coll As NameValueCollection

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

[C#]
int loop1, loop2;
NameValueCollection coll;

// Load ServerVariable collection into
NameValueCollection object.
coll=Request.ServerVariables;
// Get names of all keys into a string array.
String[] arr1 = coll.AllKeys;
for (loop1 = 0; loop1 < arr1.Length; loop1++)
{
Response.Write("Key: " + arr1[loop1] + "<br>");
String[] arr2=coll.GetValues(arr1[loop1]);
for (loop2 = 0; loop2 < arr2.Length; loop2++) {
Response.Write("Value " + loop2 + ": " + arr2
[loop2] + "<br>");
}
}
 
Back
Top