views:

538

answers:

7

I just finished my first C# project in VS 2008 and it is working well now. But now I need to publish this project on my website. This project interacts with my SQL Server 2008 Adventureworks database on this same computer.

I will use this same computer to host the website and house this database. I know HTML but not how to add a .NET project to a web site, especially one that also uses SQL Server. Can u offer me tips as to how to proceed?

I started by right-clicking the project and selecting "Convert to Web Application" and then I selected the URL for my site. But then when I went to this URL, it still shows the original image.

A: 

Asp.Net has two types of projects: website and webapplication project.

It looks like me that you are using the website project because you have the option to convert it the web application project. Right click your project, go to properties, go to "MsBuild Options" tab, you will see an Output folder, by default, it should have some path called "PrecompiledWeb", that's where your output is, and you need deploy this to your IIS directory.

J.W.
Thanks J.W., but what do I do after this?
salvationishere
I don't know, you should be good to go. Browse the website from the IIS.
J.W.
+1  A: 
  1. In IIS create a website and point it to a directory that you want to put your website in.

  2. Make sure the website properties has the default document you want and the ASP.NET tab has the framework you want.

  3. Use the menu in VS2008 to publish to this directory.

  4. Change the connection string in your Web.Config to point to the correct database.

JBrooks
JBrooks, what I like about your answer is it sounds very straight-forward. However, I have IIS 7.0 and the options are more complicated than it sounds in your solution. Can u give me more tips for which options to choose? Here's what I did: I tried adding a new website but when I right-click there is no option to add a new website from the IIS console. So instead I pointed the Home Directory of Default Web Site to my VS Project files. But this didn't change my website, so I instead changed Home Directory property to "redirection to URL" and I entered my URL. I also set IP Address...
salvationishere
IIS 7.0 is different.1. Click the "Sites" folder on the left.2. All the way on the right click "Add Web Site..."3. Point the "Physical Path" to your published directory (most of the time this is under something like C:\inetpub\wwwroot\mywebsite)4. Look at the other options (?) Save5. In the left panel you should see your site, right click and select "Manage Application" and then "Browse". Note the URL in the browser - you should have your fist site.
JBrooks
There is no "Sites" folder in IIS 7.0. There is a "Web Sites" folder, but it doesn't have Add Web Site option.
salvationishere
Isn't "Sites" the parent folder to "Default Web Sites"? Notice how the menu on the far right changes when you select different items on the far left.
JBrooks
A: 

you can't convert a windows application to a website, you have to built it from scratch.

you can go to file -> new website -> then you choose ASP.NET website.

you might also use the sqldatasource and gridview controls, they help a lot.

to run your website you can hit F5 or just right click your defalut.aspx page and select show in the browser!

check this for more information http://msdn.microsoft.com/en-us/library/41b1tfyt(VS.80).aspx hope it helps

martani_net
Martani, I'm pretty sure this is a web application. I own a book that discusses .NET Apps and there is one chapter on Windows Form applications but mine is definitely not Windows Form. Also the other two above don't seem to think it is either.
salvationishere
A: 

If your asking if you can move the location of the ASPNETDB away from the root of the project, yes, you can. There are database connection string nodes in the web.config as well as a master-default db config in your Visual studio master.config file. i think there is also a aspnetdbreg.exe or something like that to update the registration of this after you change its location.

Personally, I use visual studio 2008 and my ASPNETDB is on my SQLServer express 2008 instance. Visit my blog for more info on this stuff.

djangofan
I looked at your blog but the only blog I saw which seemed relevant to my question was the "Web Project to display Blogger RSS Feed." Is there another I should look at? I have an Application Project, not website project.
salvationishere
specifically, i was talking about this post: http://codingathome.blogspot.com/2009/04/how-to-change-location-of-aspnetdb.html . that article basically tells you how to setup the database portion of your "Application project". i cant give you advice on deploying the website/project code to the hosting provider but i thought that article might give you some ideas on the database portion of it.
djangofan
A: 

I actually just spent the last 3 weeks trying to figure out a similar question (but for an ASP.NET User Control rather than a C# project). Have a look at the answer I posted here. I can try give you more detail if you need, but I'm not sure about how you're trying to use your C# project in your website.

Matt Ball
Thanks Matt, I read thru all of your links but this didn't help much since u were using User Control instead of a C# project
salvationishere
A: 

Since you are using IIS 7.0 what you need to do is find a place for your web application to reside (e.g. C:\mywebapp).

Then open up IIS 7.0 Manager.

Expand your computer name on the left.

Expand Sites.

Right click on Default Web Site (I'm assuming you are using the Default Web Site, if you aren't substitute your site name for Default Web Site) and click on Add Application.

Type in an alias for your application. This will be the name you use to access the site (e.g. if you want the url to be http://localhost/myawesomewebapplication/ from your local machine then type in myawesomewebapplication for the alias). Click the ellipsis (the ...) next to Physical Path and browse to the folder you copied your web files to (e.g. C:\mywebapp). Click OK. Click OK to close the Add Application window.

Assuming no errors, you should now be able to browse to http://localhost/ and everything should be peachy.

smoak
I tried this, but this still didn't allow me to browse. I'm getting HTTP 403.
salvationishere
I mean HTTP 500, not HTTP 403.
salvationishere
Are you using Internet Explorer 5.0 or above to view your website? IF so make sure you have "Show Friendly Error Messages" checked.In IE go to Tools->Internet OptionsThen go to the "Advanced" tab. Scroll down and look for "Show friendly error messages". Make sure it's checked. Click OK.Now refresh your page and see if you get a different error message.
smoak
A: 

In my point of view, its simple. Let´s try:

If you want to access your DB from the web app: 1. Create an New ASP.NET Web Application (File > New > Project > Visual C# - Web) 2. In Project Properties (right button on project) go to tab "Web" and under "Servers";

Select the radio "Use Visual Studio Development Server", if you dont need to create an IIS virtual dir. Select the radio Use IIS Web server, if you need to create an IIS virtual dir. Note that you can create the directory by clicking directly the button "Create Virtual Directory".

You can create a Class Library (File > New > Project > Visual C# - Windows) to access your DB and then, reference this assembly in your Web App. Just ask if you want that way.

Erup