Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3
This is the forum to discuss the Wrox book Beginning ASP.NET 3.5: In C# and VB by Imar Spaanjaars; ISBN: 9780470187593
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 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
 
Old March 24th, 2009, 01:39 PM
Authorized User
 
Join Date: Mar 2009
Posts: 64
Thanks: 0
Thanked 1 Time in 1 Post
Default App_Code folder in "Web Application Project"

Since I am using VS 2008 Professional I decided to follow Imar's book examples but using a Web Application Project.

In Chapter 5, p. 167, he speaks of adding the App_Code folder from a set of options offered when one right clicks on the name of the site. In my case the name is actually the project name and App_Code is not offered as one of the options. Nonetheless, I like the idea of having classes grouped in a separate directory, so I manually added an App_Code folder and created the Calculator.cs file therein. FWIW, the special icon appears as described by Imar.

The project would not compile. I found a several things.

First, Web Application Projects do not offer the App_Code option, since, as described by Mikhail Arkhipov of Microsoft says at here, "You don't need App_Code in Web Application since all code files are compiled during the build, as in client projects. You can place code files anywhere in [Web Application Project]. Well not anywhere, at least not with some fussing.

Second, the properties - Build Action of Calculator.cs had to be changed from "Content" to "Compile".

Finally, the namespace, which was automatically created within Calculator.cs when I added the new item Calculator.cs to the App_Code folder of "Site.App_Code" had to be changed to just "Site".

Everything worked after all that.

Seems like a lot to go through. I tried just adding Calculator.cs to the main Site directory directly and it worked immediately. I tried using a different folder name for the code and again the namespace was "Site.foldername".

Any thoughts?

Thomas
 
Old March 24th, 2009, 03:40 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

1. Yes, correct; App_Code is not supported in a WAP. The App_Code folder is compiled at *run-time*; all code in a WAP is compiled at compile / development time. So, when you add an App_Code folder to a WAP. you end up with duplicate code; for example, a class defined in App_Code will also show up in the wap DLL. The fix is easy: just name the folder something else like Classes or CodeFiles.

2. It shouldn't be like that. When you add a new class file through the Add New Item dialog, Compile should be the default action.

3. Since all classes in a WAP are compiled into the same assembly they need unique namespaces. For a Web Site Project this isn't necessary as each folder ends up as a separate assembly. To ensure unique class names, each class is named like this:

[Folder].[SubFolder].ClassName

So, in the root they end up like this:

namespace RootNamespace

while in a sub subfolder they end up as:

namespace RootNamespace.FirstLevelFolder.SecondLevelFolder

and so on.

I am sure my recommendation in the book to follow along with a Web Site Project now makes a whole lot more sense, doesn't it? ;-)

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!
 
Old March 24th, 2009, 04:02 PM
Authorized User
 
Join Date: Mar 2009
Posts: 64
Thanks: 0
Thanked 1 Time in 1 Post
Default

Imar,

When I tried to add another class to the folder now named "Classes" it did have "Compile" as the default. Not sure now what I did earlier.

As to your recommendation - correct! However, you tempted me with the metion of "Web Application Project" and I took the bait! I am now in and will learn from it.

Thanks for your response.

Thomas

Quote:
Originally Posted by Imar View Post
2. It shouldn't be like that. When you add a new class file through the Add New Item dialog, Compile should be the default action.

I am sure my recommendation in the book to follow along with a Web Site Project now makes a whole lot more sense, doesn't it? ;-)
 
Old March 24th, 2009, 05:03 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Quote:
However, you tempted me with the metion of "Web Application Project" and I took the bait! I am now in and will learn from it.
Absolutely. You'll find that the two types have a lot in common. Once you know how to work with one, it's easy to switch to the other.... Until you start using Profile in the Personalization chapter.... ;-)

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!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Code not going as planned: "icicle" vs "savedinstancestate" joopthecat BOOK: Professional Android Application Development ISBN: 978-0-470-34471-2 3 May 3rd, 2009 03:09 PM
Chapter-5 on Intents:ContactPickerTester does not show the button "Pick a Contact" sunilm12 BOOK: Professional Android Application Development ISBN: 978-0-470-34471-2 3 April 15th, 2009 11:55 AM
Question about "Empty Project" template. Pinny BOOK: Beginning C# 3.0 : An Introduction to Object Oriented Programming ISBN: 978-0-470-26129-3 1 March 27th, 2009 11:04 AM
The Myth of "Good Web Design is in the Graphics" iminore PHP Databases 0 March 9th, 2009 02:02 PM
Earthquake Example problem "non-application token" Langley BOOK: Professional Android Application Development ISBN: 978-0-470-34471-2 2 January 28th, 2009 02:29 PM





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