1

I am working on a C# class that is a part of my ASP.Net Web Site.

Is there a simple way to output some log/debugging text to the top of the page. My class does NOT inherit from Page. I want to display variable values, etc.

The class represents an Exam object that I use in some of my aspx pages. The variables that I want to display are private and therefore inaccessible to my aspx pages.

3 Answers 3

3

Anywhere in the context of an http request you can reach the current executing page as follows.

Page page = HttpContext.Current.Handler as Page;

You are free to cast to your own page type. So you can write debug info to labels, textboxes etc.

Sign up to request clarification or add additional context in comments.

Comments

2

you can just do this

HttpContext.Current.Response.Write("your message goes here");

or write a helper method

public static void writeOut(string message) {
    HttpContext.Current.Response.Write(message);
}

Comments

2

You can try with Response.Write method

var pathOfYourLog = "";
var log = File.ReadAllLines(pathOfYourLog);
YourHttpContext.Response.Write(log);

2 Comments

Thanks. It looks like it should be HttpContext.Current.Response.Write(log) This was very helpful.
Thank's Justin i'am happy to help you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.