Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics 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 May 24th, 2004, 10:53 AM
Authorized User
 
Join Date: Mar 2004
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default Developing a web site not a web application

I'm trying to build a complete website from start to finish using Visual Studio .NET 2003. I have access to both Windows Advanced Server 2003 and Windows XP Professional.

I started my development efforts using XP, but you cannot create a web site only a web application. My problem is that a web application is created in a virtual directory of the default web site. My final product will be served as an actual web site and I'd rather not have to include the virtual path in all of the file references.

I've tried just developing from Windows Server 2003, but my experience hasn't been much better. It seems you cannot set up a web project in VS.NET without referencing a virtual directory. I'd rather develop on a port number as a complete site.

I'd imagine this problem is common, but I can't seem to find any documentation on developing a complete web site as opposed to a web application. Any tips, advice or even a guide would be greatly appreciated.

 
Old May 24th, 2004, 12:15 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Try HTML. Just kidding. What are you trying to do?

You can use WebMatrix and not use any code behinds, but you already purchased VS.NET...

 
Old May 24th, 2004, 12:40 PM
Authorized User
 
Join Date: Mar 2004
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm an experienced ASP developer, but I'm relatively new to ASP.NET. I'm familiar with Visual Studio and would like to continue using the product. I'm also using Visual Studio .NET to build C# classes that I'm using in my web sites.

I've successfully developed a few web sites using Visual Studio .NET, but I keep having this problem. I just want to build a web site, say www.mysite.com, without using virtual directories (www.mysite.com/mysite). Is this impossible with Visual Studio .NET?

There are only two ways I can think of to do it now. I could develop the web site in a virtual directory. Then when I create the site create the virtual directory within it and redirect to the virtual directory in the default.aspx page at the root of the site. I could also use Server.ApplicationPath to determine the root of the site and append it to all the links accordingly. Both of these solutions just seem incredibly undesirable. I don't want every url in my site to read www.mysite.com/mysite; why can't they just read www.mysite.com when using Visual Studio .NET?

 
Old May 24th, 2004, 12:48 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
Default

What I do is go into DNS settings and create a new Alias and point the alias to the folder in IIS. (a little more to it than that)

 
Old May 24th, 2004, 01:52 PM
Authorized User
 
Join Date: Mar 2004
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Maybe my problem is that I use root relative paths whenever referencing files. If I'm developing in a virtual directory called MySite and I have a folder called UserControls I would reference a user control using the path /MySite/UserControls/Control.ascx. This works fine in my development environment, but if I send this virtual directory live as a site the /MySite folder no longer exists because this is now the root of the site (/). The root relative path to this file becomes /UserControls/Control.ascx. The root relative path to the file changed because the root of the site changed from the Default site to MySite.

If I make the dns settings to serve the folder as a site, can I still use root relative file paths?

 
Old May 24th, 2004, 02:21 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Try using a physical path. I've never run into your problem. I treat the /mysite folder as the wwwroot folder for everything and link off of it. ie. default.aspx has a link to usercontrols/control.ascx. /mysite is never included.

 
Old May 24th, 2004, 02: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

Hi there,

It's quite possible to do what you want. Here's what you should do to create Web sites in the root on another server. There may be other ways as well, but this has always worked for me.

1. On Server 2003, create a new Web site with the Wizard. Once you created the site, open its Properties dialog and create a new HostHeader. Hostheaders allows you to have multiple sites listen to the same port number, but with different names

2. Share the folder that holds your site so it's accessible through the network

3. If the hostheader you created in step 1 is not the official name of the machine, edit the LMHosts file of your development machine, and enter a HostName IP address record for the server (e.g.MyDevelopmentSite 192.168.2.11)

4. Start a new Visual Studio Project. When asked for the location, enter http://MyDevelopmentSite Don't add the slash, or an application name.

5. When asked for the location of the files, browse to the share you created in step 2.

That's all that's necessary. You can now develop sites that are located in the root of the Web site. This allows you to use a path like /Default.aspx instead of /MySite/Default.aspx.

HtH,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old May 24th, 2004, 05:36 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Remember that a web "site" is still an application, it's just the application at the root of the site.

When you develop in Visual Studio, as you have found, you usually work in a virtual directory. There is absolutely nothing inherently wrong with this method. I develop my web site in a virtual directory but it's hosted at the root of a web URL (www.geekdork.com). The key is what you use for your URLs.

In .net you can build a URL in a server control like this: "~/myresource" When .net constructs the control, it replaces the ~ with the full path of the virtual directory (web application). Therefore, if you are developing here:

   //localhost/subdir/subdir/subdir/subdir/mywebsite

you can make a link like this:

   ~/mypage.aspx

and when the page is rendered, the actual link in the href will be this:

   /subdir/subdir/subdir/subdir/mywebsite/mypage.aspx

This applies to anything that uses a URL:
Links:
   <asp:hyperlink runat="server" href="~/mypage.aspx" />

User controls registration directives:
   <%@ Register tagprefix="tagprefix" Tagname="tagname" Src="~/myusercontrol.ascx" %>

So on and so forth. This will allow you to use root relative references without the need to write in the determination of whether you are running in a virtual directory or not.

If you want to use this functionality programmatically, there is a method on the page class for just this purpose: Page.ResolveUrl(). Just pass it the root relative URL with the ~ in it and it will give you back the complete URL with the applicable application path.

Peter
-------------------------
Work smarter, not harder
 
Old May 25th, 2004, 09:03 AM
Authorized User
 
Join Date: Mar 2004
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you all very much for your suggestions. They've turned out to be very helpful. I've decided to develop from a virtual directory and utilize the "~/directory" path format. I'm also creating a site pointing to the virtual directory as its root and using host headers to simplify the URL. It seems that this method gives me the ability to develop easily and test in a 'close to real world' environment.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Suggest to improve Web site Developing skills? Nirmalrko ASP.NET 1.0 and 1.1 Basics 4 August 24th, 2012 01:16 AM
Difference between web application and web site manojm39 ASP.NET 2.0 Basics 2 August 10th, 2007 09:06 AM
Publish Web Site & Copy Web Site angshujit ASP.NET 2.0 Basics 1 June 15th, 2007 09:21 AM
Developing a web based bio metric application umair.hasan ASP.NET 1.0 and 1.1 Professional 3 September 7th, 2006 06:50 AM
Web Application site with Dreamweaver? Jacky Kenna Dreamweaver (all versions) 1 April 6th, 2005 04:16 PM





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