Problem with ASP.NET Page Type discrepency.

V

varnk

I am using Visual Studio 2008, ASP.NET 3.5 with Forms based authentication.

I have an ASP.NET page that is doing some strange things when I try to get
the type of the page through this.GetType() vs. typeof(MyPage).

For some reason, I am getting a different result for the type. When I use
typeof(), I get what I would expect, the actual type name with namespace
(MyNameSpace.Diagnostics). When I call GetType(), I get some type with a
strange name ASP.Confidential_MyNameSpace_Diagnostics. The two types seem to
not be the same. When I try to retrieve an attribute on the class (see code
below), it does not get my class attribute because of this type problem.
Can someone tell me how to remedy this? I need to use this.GetType()
because of some design constraints not shown in the sample.

See sample code below:

namespace MyNameSpace
{
[MyAttribute()]
public partial class Diagnostics : Page {
protected void Page_Load(object sender, EventArgs e) {
Type t1, t2;
object[] attr1, attr2;

t1 = this.GetType();
attr1 = t1.GetCustomAttributes(true); // This works - I Get
MyAttribute in the array

t2 = typeof(Diagnostics);
attr2 = t2.GetCustomAttributes(true); // This does not work.
No sign of MyAttribute in the array.
}
}
}
 
A

Adrienne Boswell

Gazing into my crystal ball I observed =?Utf-8?B?dmFybms=?=
I am using Visual Studio 2008, ASP.NET 3.5 with Forms based
authentication.

I have an ASP.NET page that is doing some strange things when I try to
get the type of the page through this.GetType() vs. typeof(MyPage).

**********canned wrong newsgroup reply****************************
There was no way for you to know it (except maybe by browsing through
some of the previous questions before posting yours - always a
recommended practice), but this is a classic (COM-based) asp newsgroup.
ASP.Net is a different technology from classic ASP. While you may be
lucky enough to find a dotnet-savvy person here who can answer your
question, you can eliminate the luck factor by posting your question to
a newsgroup where the dotnet-savvy people hang out. I suggest

microsoft.public.dotnet.framework.aspnet.

There are also forums at www.asp.net where you can find a lot of people
to help you.
**********canned wrong newsgroup reply****************************
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,794
Messages
2,569,641
Members
45,355
Latest member
SJLChristi

Latest Threads

Top