Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 can we put trace.write in a class outside the page

Author  Topic 

rtutus
Aged Yak Warrior

522 Posts

Posted - 2006-10-19 : 14:27:23

Hi , I have my aspx page and its code behind.
In the code behind, I call a method within another business class. So my business class doesn t inherit from Web class.
Can I place Trace.write in the business class although it doesn t correspond to a specific page or we only can put Trace.write in classes that are the code behind of an aspx class

Thank you

MichaelP
Jedi Yak

2489 Posts

Posted - 2006-10-19 : 16:00:44
I think to do something like that, the Business class would need to raise an event that passes the text to be "trace.written", the web page class would need to handle that event, and call trace.write.

It's not super easy, but I think it can be done.

Michael

<Yoda>Use the Search page you must. Find the answer you will. Cursors, path to the Dark Side they are. Avoid them, you must. Use Order By NewID() to get a random record you will.</Yoda>

Opinions expressed in this post are not necessarily those of TeleVox Software, inc. All information is provided "AS IS" with no warranties and confers no rights.
Go to Top of Page

snSQL
Master Smack Fu Yak Hacker

1837 Posts

Posted - 2006-10-19 : 16:14:57
Yes you can, like this

1. In the business class project, add a reference to System.Web.dll
2. Add a namespace reference at the top of your class file
using System.Web;

3. In your class method/s you then get to the Trace for the page that called the method like this
HttpContext.Current.Trace.Write("My Category", "My Message");


Note that the HttpContext actually gives you access to pretty much everything that's available in the page, like the Request and Response too.
Go to Top of Page

rtutus
Aged Yak Warrior

522 Posts

Posted - 2006-10-20 : 14:11:11
cool thanks a lot.
Go to Top of Page
   

- Advertisement -