Solved

Where is the Message object that was in VS 2008

Posted on 2013-05-31
6
454 Views
Last Modified: 2013-06-05
This worked in VS 2008. It is Error Handler code

      <asp:LinkButton ID="DetailLinkButton" runat="server"
            OnClick="DetailLinkButton_Click">Show Details
        </asp:LinkButton>

protected void DetailLinkButton_Click(object sender, EventArgs e)
        //Displays error details only to the web master
        {
            if (this.MessagePanel.Visible)
            {
                this.MessagePanel.Visible = false;
                this.DetailLinkButton.Text = "Show Details";
            }
            else
            {
                if (Message.LastException != null)
                {
                    this.MessageTextBox.Text = "Error Caught in Application_Error event\n" +
                        "Error in: " + Request.Url.ToString() +
                        "\n\nError Message:" + Message.LastException.Message.ToString() +
                        "\n\nStack Trace:" + Message.LastException.StackTrace.ToString();
                }
                else
                {
                    //this should never happen.
                    this.MessageTextBox.Text = "There is no exception.";
                }

Error in 2012

Error      1      The name 'Message' does not exist in the current context      C:\Users\Dovberman\Documents\Visual Studio 2012\Projects\StockPro\WebApplication1\ErrorHandling\ShowError.aspx.cs      93      21      StockPro

What replaces the Message object in vs 2012 ?

Thanks
0
Comment
Question by:Dovberman
  • 4
  • 2
6 Comments
 
LVL 34

Expert Comment

by:Paul MacDonald
ID: 39211432
I'm not familiar with a Message object in ASP.Net C# or VB.  Is it possible this was a user-defined class that didn't make it over (or was renamed) from VS2k8?
0
 

Author Comment

by:Dovberman
ID: 39211616
I partially fixed this.

http://bytes.com/topic/asp-net/answers/564850-global-error-handler

Added this line to the web.config file:

<!--
            The <customErrors> section enables configuration
            of what to do if/when an unhandled error occurs
            during the execution of a request. Specifically,
            it enables developers to configure html error pages
            to be displayed in place of a error stack trace.
            -->
    <customErrors mode="On" defaultRedirect="~/ErrorHandling/ShowError.aspx">
    </customErrors>

Message.LastException seems to be an error object.

Again, this worked in VS 2008 in .net 2.0.
0
 
LVL 34

Expert Comment

by:Paul MacDonald
ID: 39211619
Interesting.

What part still doesn't work?
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

by:Dovberman
ID: 39211752
if (Message.LastException != null)


Error      1      The name 'Message' does not exist in the current context      C:\Users\Dovberman\Documents\Visual Studio 2012\Projects\StockPro\WebApplication1\Global.asax.cs      16      9      StockPro

The message object was part of the exception class in vs 2008.

Message.LastException  represented the most recent error that was passed to the error handler.

Is there is new way to handle errors in vs 2012 using .net 4.5?
0
 

Accepted Solution

by:
Dovberman earned 0 total points
ID: 39212158
I removed this block of code that displayed the error message only if Admin was logged on.

I will display the exception detail to the Web Master within the Catch block instead .

protected void DetailLinkButton_Click(object sender, EventArgs e)
        //Displays error details only to the web master
        {
            if (this.MessagePanel.Visible)
            {
                this.MessagePanel.Visible = false;
                this.DetailLinkButton.Text = "Show Details";
            }

            else
            {
                if (Message.LastException != null)
                {
                    this.MessageTextBox.Text = "Error Caught in Application_Error event\n" +
                        "Error in: " + Request.Url.ToString() +
                        "\n\nError Message:" + Message.LastException.Message.ToString() +
                        "\n\nStack Trace:" + Message.LastException.StackTrace.ToString();
                }
                else
                {
                    //this should never happen.
                    this.MessageTextBox.Text = "There is no exception.";
                }

                this.MessagePanel.Visible = true;
                this.DetailLinkButton.Text = "Hide Details";
            }}
0
 

Author Closing Comment

by:Dovberman
ID: 39221525
I resolved this issue myself.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question