Solved

Where is the Message object that was in VS 2008

Posted on 2013-05-31
6
453 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 33

Expert Comment

by:paulmacd
Comment Utility
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
Comment Utility
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 33

Expert Comment

by:paulmacd
Comment Utility
Interesting.

What part still doesn't work?
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:Dovberman
Comment Utility
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
Comment Utility
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
Comment Utility
I resolved this issue myself.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now