locked
Tracing in web.config vs @Page RRS feed

  • Question

  • User977690511 posted

    According to http://msdn.microsoft.com/en-us/library/94c55d08(v=vs.100).aspx, it says:

    The Trace attribute in the @ Page directive takes precedence over attributes set in the trace element in the Web.config file. Therefore, even if you disable tracing in the Web.config file by setting the enabled attribute to false, the page might still show tracing information if the Trace attribute in its @ Page directive is set to true.

    I find that if I have Trace='true' in the @Page directive of a page and <trace enabled='false' /> in web.config, no tracing takes place.  But if I have <trace enabled='true' /> every page leaves a trace.

    How do I have selective Trace in certain pages?

     

    Wednesday, August 21, 2013 1:03 AM

Answers

  • User-1454326058 posted

    Hi hc1,<o:p></o:p>

    Based on you said "My problem is that according to Microsoft's document, having <trace enabled='false' /> in web.config will still collect traces from those pages that have Trace='true' in their @Page directive but I find this not working for me", I tried in Visual Studio 2010 and Visual Studio 2012 and it's working for me. (Trace information to appear at the end of the page)<o:p></o:p>

    A: Enable trace in web.config and haven't set trace in each page. The result is that it will collect trace information for each page.<o:p></o:p>

    B: Enable trace in web.config and disenable trace in PageA. The result is that it will collect trace information for each page except PageA<o:p></o:p>

    C: Disenable trace in web.config and enable trace in PageA. The result is that it will only collect trace information for PageA.<o:p></o:p>

    So I can’t reproduce your scene. I would like to know what’s version of your Visual Studio.<o:p></o:p>

    Please try something as follows:<o:p></o:p>

    1.  Create a new project and try it, check the result.

    2.  Clean your project and rebuild, then try it and check the result.

    3.  Clean your web browser cookie, then try it and check the result.

    Thanks<o:p></o:p>

    Best Regards<o:p></o:p>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, August 24, 2013 5:02 AM

All replies

  • User-1716253493 posted
    Page setting in web.config will become default for all pages. @ Page directive will replace the default setting for the page.
    Wednesday, August 21, 2013 1:13 AM
  • User977690511 posted

    Sorry, is there another Page setting in web.config in addition to <trace> in <system.web>?

    Wednesday, August 21, 2013 2:08 AM
  • User-1454326058 posted

    Hi hc1,

    Thanks for your post!

    In my opinion, configure Tracing in web.config file is the best way. Based on your requirement, here are some reference below that maybe can benefit you. 

    Tracing in ASP.NET Web API

    http://www.asp.net/web-api/overview/testing-and-debugging/tracing-in-aspnet-web-api

    ASP.NET Web API Tracing (Preview)

    http://blogs.msdn.com/b/roncain/archive/2012/08/16/asp-net-web-api-tracing-preview.aspx

    Thursday, August 22, 2013 8:53 AM
  • User977690511 posted

    Starain, thanks. 

    My requirement is very simple: to collect traces for a few selected pages.  I don't want to introduce more code to complicate the issue and possibly introduce more problems.  The most I want to use is Trace.Warn() in code-behind.

    My problem is that according to Microsoft's document, having <trace enabled='false' /> in web.config will still collect traces from those pages that have Trace='true' in their @Page directive but I find this not working for me.  When trace is disabled in web.config, no traces are collected.  It's either traces on all pages or nothing.  I want to troubleshoot one page but its trace is mixed up in a very long list of traces from other pages.  I wonder if everyone else has the same experience or whether if I have done anything wrong.

    Thursday, August 22, 2013 11:45 AM
  • User-1454326058 posted

    Hi hc1,<o:p></o:p>

    Based on you said "My problem is that according to Microsoft's document, having <trace enabled='false' /> in web.config will still collect traces from those pages that have Trace='true' in their @Page directive but I find this not working for me", I tried in Visual Studio 2010 and Visual Studio 2012 and it's working for me. (Trace information to appear at the end of the page)<o:p></o:p>

    A: Enable trace in web.config and haven't set trace in each page. The result is that it will collect trace information for each page.<o:p></o:p>

    B: Enable trace in web.config and disenable trace in PageA. The result is that it will collect trace information for each page except PageA<o:p></o:p>

    C: Disenable trace in web.config and enable trace in PageA. The result is that it will only collect trace information for PageA.<o:p></o:p>

    So I can’t reproduce your scene. I would like to know what’s version of your Visual Studio.<o:p></o:p>

    Please try something as follows:<o:p></o:p>

    1.  Create a new project and try it, check the result.

    2.  Clean your project and rebuild, then try it and check the result.

    3.  Clean your web browser cookie, then try it and check the result.

    Thanks<o:p></o:p>

    Best Regards<o:p></o:p>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, August 24, 2013 5:02 AM