Prev: How to log more info on System.Web.HttpException: Request timed ou
Next: How to log more info on System.Web.HttpException: Request time
From: varnk on 12 Mar 2010 17:13 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. } } } |