Solved

Where is the Message object that was in VS 2008

Posted on 2013-05-31
6
456 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

738 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