Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > BOOK: Beginning ASP.NET 4 : in C# and VB
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
BOOK: Beginning ASP.NET 4 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 10th, 2013, 12:02 PM
Friend of Wrox
Points: 595, Level: 8
Points: 595, Level: 8 Points: 595, Level: 8 Points: 595, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2011
Posts: 126
Thanks: 39
Thanked 2 Times in 2 Posts
Default ch 18 - Try It out: Handling Exceptions Site Wide

Hi Imar,

I'm unable to see the "File Not Found" custom error page when requesting DefaultTest.aspx.

I went back and checked to confrim that I can direclty request the 2 custom error pages. I also checked the syntax of the customErrors section in the web.config file. Just to make sure, I copied the customErrors section from the provided web.config file under the source directory.

When requesting DefaultTest.aspx, I get the following error:

Server Error in '/' Application.

The resource cannot be found.

Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

Requested URL: /DefaultTest.aspx

Any ideas as to what I'm doing wrong?

Thank you.

Tulsi
Reply With Quote
  #2 (permalink)  
Old April 10th, 2013, 12:08 PM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Can you post your code code for the following files:

1. Web.config

2. The 404 page (markup and code behind)

3. The Global.asax?

If you post code, can you please paste it in Notepad first to remove color coding and then use the forum editor's Code toolbar button to wrap your code in code tags. Otherwise, this forum messes up the code.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #3 (permalink)  
Old April 10th, 2013, 12:47 PM
Friend of Wrox
Points: 595, Level: 8
Points: 595, Level: 8 Points: 595, Level: 8 Points: 595, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2011
Posts: 126
Thanks: 39
Thanked 2 Times in 2 Posts
Default

Hi Imar,

I copied the code to notepad first and then copied over to the forum... Hope that I did not miss anything.

1. Web.config:

Code:
<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <connectionStrings>
    <add name="PlanetWroxConnectionString1" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\PlanetWrox.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient" />
    <add name="PlanetWroxEntities" connectionString="metadata=res://*/App_Code.PlanetWrox.csdl|res://*/App_Code.PlanetWrox.ssdl|res://*/App_Code.PlanetWrox.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.\SQLEXPRESS;attachdbfilename=|DataDirectory|\PlanetWrox.mdf;integrated security=True;user instance=True;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
    <add name="PlanetWroxEntities1" connectionString="metadata=res://*/App_Code.PlanetWroxToDelete.csdl|res://*/App_Code.PlanetWroxToDelete.ssdl|res://*/App_Code.PlanetWroxToDelete.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.\SQLEXPRESS;attachdbfilename=|DataDirectory|\PlanetWrox.mdf;integrated security=True;user instance=True;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
  <system.web>
      <customErrors mode="On" defaultRedirect="~/Errors/OtherErrors.aspx" redirectMode="ResponseRewrite">
          <error statusCode="404" redirect="~/Errors/Error404.aspx"/>
      </customErrors>
      <anonymousIdentification enabled="true" cookieName="PlanetWroxAnonymous"/>
    <profile>
      <properties>
        <add name="FirstName" />
        <add name="LastName" />
        <add name="DateOfBirth" type="System.DateTime" />
        <add name="Bio" />
        <add name="FavoriteGenres" type="System.Collections.Generic.List`1[System.Int32]" />
        <add name="FavoriteTheme" defaultValue="Monochrome" allowAnonymous="true"/>
      </properties>
    </profile>
    <roleManager enabled="true" />
    <membership>
      <providers>
        <clear />
        <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, &#xD;&#xA;                 Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="LocalSqlServer" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" applicationName="/" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="1" passwordAttemptWindow="10" passwordStrengthRegularExpression="" />
      </providers>
    </membership>
    <authentication mode="Forms" />
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
        <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
        <add assembly="System.Data.Entity.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
      </assemblies>
      <buildProviders>
        <add extension=".edmx" type="System.Data.Entity.Design.AspNet.EntityDesignerBuildProvider" />
      </buildProviders>
    </compilation>
    <pages theme="Monochrome">
      <controls>
        <add tagPrefix="Wrox" tagName="Banner" src="~/Controls/Banner.ascx" />
      </controls>
    </pages>    
  </system.web>
  <system.net>
    <mailSettings>
      <smtp deliveryMethod="Network" from="Venu Amish Mehta &lt;venum83@sbcglobal.net&gt;">
        <network host="smtp.sbcglobal.yahoo.com" userName="venum83@sbcglobal.net" password="02Ya05Sh" />
      </smtp>
    </mailSettings>
  </system.net>
  <location path="Management">
    <system.web>
      <authorization>
        <allow roles="Managers" />
        <deny users="*" />
      </authorization>
    </system.web>
  </location>
  <location path="MyProfile.aspx">
    <system.web>
      <authorization>
        <deny users="?" />
      </authorization>
    </system.web>
  </location>
   <location path="ManagePhotoAlbum.aspx">
        <system.web>
            <authorization>
                <deny users="?" />
            </authorization>
        </system.web>
   </location>
    <location path="NewPhotoAlbum.aspx">
        <system.web>
            <authorization>
                <deny users="?" />
            </authorization>
        </system.web>
    </location>
</configuration>
2. 404 page:

Code Behind:

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Errors_Error404 : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Status = "404 Not Found";
        Response.StatusCode = 404;

    }
}
MarkUp:

Code:
<%@ Page Title="File Not Found" Language="C#" MasterPageFile="~/MasterPages/FrontEnd.master" AutoEventWireup="true" CodeFile="Error404.aspx.cs" Inherits="Errors_Error404" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cpMainContent" Runat="Server">
    <h1>File Not Found</h1>
    <p>The page you requested could not be found.  Please check out the <a href="~/" runat="server">HomePage</a> or choose a different page from the menu. </p>
    <p>The Planet Wrox Team</p>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="cpClientScript" Runat="Server">
</asp:Content>
3. Global.asax

Code:
<%@ Application Language="C#" %>
<%@ Import Namespace="System.Net.Mail" %>

<script runat="server">

    void Application_Start(object sender, EventArgs e) 
    {
        // Code that runs on application startup

    }
    
    void Application_End(object sender, EventArgs e) 
    {
        //  Code that runs on application shutdown

    }
        
    void Application_Error(object sender, EventArgs e) 
    { 
        // Code that runs when an unhandled error occurs
        if (HttpContext.Current.Server.GetLastError() != null)
        {
            Exception myException = HttpContext.Current.Server.GetLastError().GetBaseException();
            
            string mailSubject = "Error in page " + Request.Url.ToString();
            string message = string.Empty;
            message += "<strong>Message</strong><br />" + myException.Message + "<br />";
            message += "<strong>StackTrace</strong><br />" + myException.StackTrace + "<br />";
            message += "<strong>Query String</strong><br />" + Request.QueryString.ToString() + "<br />";

            MailMessage myMessage = new MailMessage("venum83@sbcglobal.net", "venum83@sbcglobal.net", mailSubject, message);
            myMessage.IsBodyHtml = true;
            SmtpClient mySmtpClient = new SmtpClient();
            mySmtpClient.Send(myMessage);
        }

    }

    void Session_Start(object sender, EventArgs e) 
    {
        // Code that runs when a new session is started

    }

    void Session_End(object sender, EventArgs e) 
    {
        // Code that runs when a session ends. 
        // Note: The Session_End event is raised only when the sessionstate mode
        // is set to InProc in the Web.config file. If session mode is set to StateServer 
        // or SQLServer, the event is not raised.

    }
       
</script>
thanks,
Tulsi
Reply With Quote
  #4 (permalink)  
Old April 11th, 2013, 02:58 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Tulsi,

I copied your code into my Planet Wrox web site, and it worked as expected. The only thing I had to fix was this:

System.Web, &#xD;&#xA;

Notice the odd characters and spaces that shouldn't be there. Not sure if that came from posting here......

Could it be that you have an issue in your web.config or elsewhere in your site? Do you run into this when working with Visual Studio and the development server or do you have this issue when you use IIS?

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #5 (permalink)  
Old April 11th, 2013, 12:50 PM
Friend of Wrox
Points: 595, Level: 8
Points: 595, Level: 8 Points: 595, Level: 8 Points: 595, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2011
Posts: 126
Thanks: 39
Thanked 2 Times in 2 Posts
Default

Imar,

I'm working with Visual Studio and the development server.

I removed the odd characters and spaces from the file, but I'm still unable to see the "File Not Found" custom error page when requesting DefaultTest.aspx.

I'm not sure how to troubleshoot this issue?

Thank you.
Tulsi
Reply With Quote
  #6 (permalink)  
Old April 11th, 2013, 01:16 PM
Friend of Wrox
Points: 595, Level: 8
Points: 595, Level: 8 Points: 595, Level: 8 Points: 595, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2011
Posts: 126
Thanks: 39
Thanked 2 Times in 2 Posts
Default

Hi Imar,

Just tried one more thing which seemed to work.

I re-read the "Common Mistakes" section on p.670 and I recreated the Error404 Page as a standard Web Form not using my master page and base page. This seemed to fix the problem.

As you mentioned in this section, the problem was accessing the Profile in the basepage class.

Is it standard practice to create these custom error pages as standard web forms and not use the available master pages for the web application?

Thank you again for looking at this problem.

Tulsi
Reply With Quote
  #7 (permalink)  
Old April 11th, 2013, 01:18 PM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Ah, yes, I was just going to ask... ;-)

>> Is it standard practice to create these custom error pages as standard web forms and not use the available master pages for the web application?

It depends. If you want to access profile, you have no other option. Many sites don't have a theme selector or other functionality that requires access to Profile in a custom error page, so oftentimes this is not an issue.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #8 (permalink)  
Old April 11th, 2013, 01:22 PM
Friend of Wrox
Points: 595, Level: 8
Points: 595, Level: 8 Points: 595, Level: 8 Points: 595, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2011
Posts: 126
Thanks: 39
Thanked 2 Times in 2 Posts
Default

Thank you so much again!!

Tulsi
Reply With Quote
  #9 (permalink)  
Old September 11th, 2013, 07:36 AM
Registered User
Points: 30, Level: 1
Points: 30, Level: 1 Points: 30, Level: 1 Points: 30, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2013
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

in p668, you ask to use the custom template.
If you can get it when you do not use, does that mean the mistake is in template?
Reply With Quote
  #10 (permalink)  
Old September 12th, 2013, 10:29 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

I don't understand the question. Can you elaborate?

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Site-Wide Registration of User Controls Khalil BOOK: Beginning ASP.NET 4 : in C# and VB 25 October 7th, 2011 03:21 AM
Handling Exceptions - invalid email address Mind Games BOOK: Beginning ASP.NET 4 : in C# and VB 3 April 30th, 2011 09:56 AM
Ch 18 Deploying Your Web Site jtruffa BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 3 August 24th, 2009 07:29 AM
C# handling SQL Server exceptions booksnore2 General .NET 3 September 16th, 2006 09:40 AM
Site Wide Enum - Best Practice rodmcleay ASP.NET 1.0 and 1.1 Professional 8 June 8th, 2004 08:03 AM



All times are GMT -4. The time now is 01:14 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.