Solved

Where is the Message object that was in VS 2008

Posted on 2013-05-31
6
455 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
How our DevOps Teams Maximize Uptime

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

 

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!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

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…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
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…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

820 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