Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning ASP.NET 4.5 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4.5: in C# and VB by Imar Spaanjaars; ISBN: 978-1-118-31180-6
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4.5 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 9th, 2015, 12:50 PM
Registered User
Points: 19, Level: 1
Points: 19, Level: 1 Points: 19, Level: 1 Points: 19, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2015
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 6 BasePage

Hi. I'm currently trying to design a website using a basepage but I am running into a problem when I upload it to a server.

CS0246: The type or namespace name 'BasePage' could not be found (are you missing a using directive or an assembly reference?)

I'm trying to have my index(home page) inherit from basepage. The code I used to make that happen is seen below

-Index Page 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 Index : BasePage
{
protected void Page_Load(object sender, EventArgs e)
{

}
}

-Base Page Code-

using System;
using System.Web;

public class BasePage : System.Web.UI.Page
{
private void Page_PreInit(object send, EventArgs e)
{
HttpCookie preferredTheme = Request.Cookies.Get("PreferredTheme");
if (preferredTheme != null)
{
string folder = Server.MapPath("~/App_Themes/" + preferredTheme.Value);
{
Page.Theme = preferredTheme.Value;
}
}
}
private void Page_PreRender(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(this.Title) || this.Title.Equals("Untitled Page",
StringComparison.CurrentCultureIgnoreCase))
{
throw new Exception(
"Page title cannot be \"Untitled Page\" or an empty string.");
}
}
public BasePage()
{
this.PreRender += Page_PreRender;
this.PreInit += Page_PreInit;
}
}

What is the problem because I have no idea?
EDIT:My basepage.cs is in App_Code folder btw
Reply With Quote
  #2 (permalink)  
Old March 9th, 2015, 03:11 PM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi there,

Is your site in the root of the server? If not, and it's in a sub folder, it may not be looking in the correct App_Code folder.

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 March 9th, 2015, 03:57 PM
Registered User
Points: 19, Level: 1
Points: 19, Level: 1 Points: 19, Level: 1 Points: 19, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2015
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That is indeed the case. What change need to be made to the code to make sure its looking at the right app-code folder then? (I'm not in charge of the server so I can make no changes on that end)
Reply With Quote
  #4 (permalink)  
Old March 10th, 2015, 04:39 PM
Registered User
Points: 19, Level: 1
Points: 19, Level: 1 Points: 19, Level: 1 Points: 19, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2015
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Does anyone know what change i need to make basepage work?(again no access to the server side of things)

Reposted code with correct tags.
index page code
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 Index : BasePage
{
protected void Page_Load(object sender, EventArgs e)
{

}
}
basepage code
Code:
using System;
using System.Web;

public class BasePage : System.Web.UI.Page
{
private void Page_PreInit(object send, EventArgs e)
{
HttpCookie preferredTheme = Request.Cookies.Get("PreferredTheme");
if (preferredTheme != null)
{
string folder = Server.MapPath("~/App_Themes/" + preferredTheme.Value);
{
Page.Theme = preferredTheme.Value;
}
}
}
private void Page_PreRender(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(this.Title) || this.Title.Equals("Untitled Page",
StringComparison.CurrentCultureIgnoreCase))
{
throw new Exception(
"Page title cannot be \"Untitled Page\" or an empty string.");
}
}
public BasePage()
{
this.PreRender += Page_PreRender;
this.PreInit += Page_PreInit;
}
}
Reply With Quote
  #5 (permalink)  
Old March 11th, 2015, 11:10 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi there,

There's not much you can do. App_Code needs to be in the root of the application. That means either at the server level (e.g.: www.yourdomain.com/App_Code) or at the application level (e.g. www.yourdomain.com/AppName/App_Code). In the latter case, AppName needs to be configured as a separate application (and not just a folder) in IIS the web server, which needs to be done by an administrator on the serve.

Maybe you can ask your host to configure this for you?

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
  #6 (permalink)  
Old March 11th, 2015, 03:25 PM
Registered User
Points: 19, Level: 1
Points: 19, Level: 1 Points: 19, Level: 1 Points: 19, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2015
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok I'll try. Is their a way to set-up a page to be able to switch themes with a dropdownlist without using basepage. If their is I can do that instead.
Reply With Quote
  #7 (permalink)  
Old March 11th, 2015, 04:22 PM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

You could set the theme in each page individually. Or you could try to set it in the Master Page as that would apply it to all pages that use that master.

But I would recommend trying to get a better hosting setup, as you'll run into lots of other issues if you can't use the App_Code or Bin folders.

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 March 30th, 2015, 01:38 AM
Registered User
Points: 19, Level: 1
Points: 19, Level: 1 Points: 19, Level: 1 Points: 19, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2015
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

[UPDATE]My instructor has been working on resolving this issue server side and while he has fixed the basepage issue(at least as far I know he has) a new problem is now present.

The file '/MasterPages/Frontend.master' does not exist.

Code:
<%@ Page Title="main" Language="C#" MasterPageFile="~/MasterPages/Frontend.master" AutoEventWireup="true" CodeFile="Index.aspx.cs" Inherits="Index" %>
It is in a folder called MasterPages and is titled Frontend.master. I wanted to ask if this was still a problem with the server or if this is something I could fix on my end?

Also I noticed this on the error page:
Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.34237

That is not version 4.5 right? If its not could that be whats causing all the problems?
Reply With Quote
  #9 (permalink)  
Old April 4th, 2015, 04:04 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi there,

It sounds like the same issue: an incorrect folder structure where your site is either not in the root of the server, or it's not marked as an application in IIS so it has its own root. Can you provide more details about your site's structure, the URL you use and the way the server has been configured?

>> That is not version 4.5 right?

It could be. The .NET Famework 4.5 uses the .NET runtime 4.0; you see the latter version number here.

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
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
Chapter 6 BasePage & Template Try It Out PhilC BOOK: Beginning ASP.NET 4 : in C# and VB 7 April 4th, 2013 02:54 PM
Basepage Khalil BOOK: Beginning ASP.NET 4 : in C# and VB 3 December 7th, 2011 06:42 AM
BasePage Question Rushino BOOK: Beginning ASP.NET 4 : in C# and VB 9 April 9th, 2010 12:48 PM
chapter 6 p226 preferred theme in basepage robbaralla BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 7 November 7th, 2009 11:24 AM
BasePage Code for VB (Chapter 6) justinjones06 BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 1 September 15th, 2008 01:50 AM



All times are GMT -4. The time now is 08:24 PM.


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