473,544 Members | 1,865 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Accessing Custom Attributes in an HttpModule

I have a custom attribute that I attach to certain pages in my application and I want to inspect each page request as it is made to see if the custom attribute is attached to the underlying page class. If is attached I want to perform some action.

How can I access custom attributes from an HttpModule? I have to pass a target to the
System.Attribut e.GetCustomAttr ibute() call to attempt to retrieve the attached attribute.

I tried to access the attribute from global.asax using the Request and HttpContext as the target and it doesn't work (which I figured it wouldn't). If call System.Attribut e.GetCustomAttr ibute() in the Page's load event I can access it by passing a reference to 'this' as the target param.

What should I pass to the GetCustomAttrib ute call in an HttpModule to have it inspect the uderlying page class that generated the current request being processed?

Thanks
Michael
Nov 18 '05 #1
3 3741
// get current page

System.Web.UI.P age myPage = HttpContext.Cur rent.Handler;
-- bruce (sqlwork.com)
"Michael Iantosca" <ms*******@edef ine.com> wrote in message
news:E8******** *************** ***********@mic rosoft.com...
I have a custom attribute that I attach to certain pages in my application and I want to inspect each page request as it is made to see if the custom
attribute is attached to the underlying page class. If is attached I want to
perform some action.
How can I access custom attributes from an HttpModule? I have to pass a target to the System.Attribut e.GetCustomAttr ibute() call to attempt to retrieve the attached attribute.
I tried to access the attribute from global.asax using the Request and HttpContext as the target and it doesn't work (which I figured it wouldn't).
If call System.Attribut e.GetCustomAttr ibute() in the Page's load event I
can access it by passing a reference to 'this' as the target param.
What should I pass to the GetCustomAttrib ute call in an HttpModule to have it inspect the uderlying page class that generated the current request being
processed?
Thanks
Michael

Nov 18 '05 #2
Hi A.M,
Thank you for using MSDN Newsgroup! My name is Steven, and I'll be
assisting you on this issue.
From your description, you've create a custom attribute for a Page class
which is used to perform as the base class of the pages in your web
application. Since you want to do some operations based on this custom
attribute at the begining of a request, you're looking for some approachs
to attrieve the Page's class in a certain HttpModule so as to use the class
to retreive the custom attribute.
If there is anything I misunderstood, please feel free to let me know.

Based on my research, in ASP.NET runtime, we can retrieve the request's
related page class(IHttpHand ler) just as bruce barker said, using the
"HttpContext.Cu rrent.Handler". By default, if you haven't specified a
certain custom HttpHandler for the certain type of request,
"HttpContext.Cu rrent.Handler" is just the requested page's class. However,
the problem now is when could we retrieve it.
Generaly the whole sequence a ASP.NET request is processed is called the
ASP.NET pipeline. Once the request makes it in to the worker process, it
goes throught a series of steps and classes before it arrives at the
ultimate handler(by default is a certain page class). The simple sequence
is :

HttpWorkerReque st created--------->HttpRuntime class create a new instance
of HttpContext class ------------>the HttpContext instance generate other
necessary instance such as HttpRequest, HttpResponse... ----------->The
ApplicationFact ory create a certain HttpApplication instance and the
HttpApplication instance initialize itself--------------> The HttpModules
are created instances and serve the request---------------->
HttpHandlerFact ory create the instance of the correct HttpHandler(the page
class) and the HttpHandler calls its "ProcessReqeust " Method. Once the
ProcessRequest method returns, the request is complete.

For detailed infos on the ASP.NET runtime pipeline, you can view the
following tech article in MSDN:
#The ASP.NET HTTP Runtime
http://msdn.microsoft.com/library/en...PNETHTTPRuntim
e.asp?frame=tru e
So we could notice that the HttpHandler( the page class) is created at the
end of the pipeline. When the HttpModules instances are created, the
HttpHandler instance hasn't been created yet. So that means we can't
retrieve the Page class(HttpHandl er) instance at that time.

Since the means using HttpModule fails, I've also tried retrieved the
HttpHandler in the Global object's Application events, such as
"Application_Be ginRequest", "Application_En dRequest",
"Application_Au thenticateReque st" However, only in the
"Application_En dRequest" can I retrieve the page ( HttpHandler) instance
via the "HttpContext.Cu rrent.Handler", but I don't think the EndRequest is
the time you want.

So I haven't found a place other than the Page's event such as "Init" or
"Load" that could I got the HttpHandler instance so far. As you want to do
some modification based on the custom attribute of the page class, do you
think is possible to move the operation to other later event such as
"Page_Init" ? Or do you think we can look for any other means to workaround
this?

Please check out the preceding suggestions. If you have any questions or
need any help, please feel free to let me know.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Nov 18 '05 #3
Check out this article:
http://www.codeproject.com/aspnet/De...balization.asp. It shows how
to process custom attributes in a page and controls from a HttpModule.

Regards,
Sami

"Michael Iantosca" <ms*******@edef ine.com> wrote in message
news:E8******** *************** ***********@mic rosoft.com...
I have a custom attribute that I attach to certain pages in my application and I want to inspect each page request as it is made to see if the custom
attribute is attached to the underlying page class. If is attached I want to
perform some action.
How can I access custom attributes from an HttpModule? I have to pass a target to the System.Attribut e.GetCustomAttr ibute() call to attempt to retrieve the attached attribute.
I tried to access the attribute from global.asax using the Request and HttpContext as the target and it doesn't work (which I figured it wouldn't).
If call System.Attribut e.GetCustomAttr ibute() in the Page's load event I
can access it by passing a reference to 'this' as the target param.
What should I pass to the GetCustomAttrib ute call in an HttpModule to have it inspect the uderlying page class that generated the current request being
processed?
Thanks
Michael

Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
454
by: Doug Holland | last post by:
Often you see code where an empty interface is used to indicate something about the class that realizes it. In the .NET world this can be done with custom attributes too, so which is better: public class SomeClass : IEmptyInterface or
3
2875
by: xAvailx | last post by:
I apologize ahead of time for the long post... Background: Working on a CRM type custom application. The application is for an event management company. The company will provide the application for other organizations to manage their own events. The events include conferences, corp meetings, sales meetings, etc... An event planner will...
8
2173
by: nicolas.sanguinetti | last post by:
Hi, I want to add custom attributes to my xhtml documents to use with my DOM scripts. For example, I want to have some tags -say, the <h1>- have an attribute and a . The thing is that I also want the document to validate against xhtml 1.1 :-) How can I define a Schema (and embed it in my xhtml) to expand XHTML default and add this...
1
2134
by: Bret Pehrson | last post by:
I've converted a non-trivial C++ library to managed, and get the following unhelpful linker error: Assignment.obj : error LNK2022: metadata operation failed (80131195) : Custom attributes are not consistent: (0x0c0001a5). Display.obj : error LNK2022: metadata operation failed (80131195) : Custom attributes are not consistent: (0x0c000108)....
3
2130
by: Edward Diener | last post by:
I understand the syntax of custom attributes, but I have no idea what they are supposed to do. Anyone care to give me a clue as to their functionality ?
1
4186
by: Tamas Demjen | last post by:
I started to experiment with VC++ 2005 Beta1. So far everything went fine, and already have a working project, but soon I realized that the compiler was ancient (not supporting half of the C++/CLI standard). So I downloaded the VC++ 2005 Tools Refresh (http://tinyurl.com/5mdq2). After that I tried to do a full rebuild, but my project wouldn't...
3
3173
by: Mark R. Dawson | last post by:
Hi all, I am trying to get custom attributes from a property. I can do this if I pass in the name of the property i.e. "Name" to the reflection methods, but if I pass in set_Name which is what the set piece of the Name property gets compiled to, which I am getting from the stack trace, then the attributes are not returned. For example,...
2
2511
by: prabhupr | last post by:
Hi Folks I was reading this article (http://www.dotnetbips.com/articles/displayarticle.aspx?id=32) on "Custom Attribute", written by Bipin. The only thing I did not understand in this article is the usage of "Custom Attribute" in real life project. Can somebody please help me understand where are these informations really helpful in...
1
1515
camel
by: camel | last post by:
Apologies if foolish question, but I somewhat expected Custom Attributes (i.e. inheriting from System.Attribute) decorating class properties to come through via WSDL to the proxy the same as built in Attributes (e.g., Xml .Serialization attributes). Have typically always accessed custom attributes in referenced assemblies rather than...
0
7431
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7370
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7779
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
5920
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5305
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3424
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1848
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
992
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
674
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.