简体   繁体   English

如何将.NET C#项目添加到网站?

[英]How to add a .NET C# project to a web site?

I just finished my first C# project in VS 2008 and it is working well now. 我刚刚在VS 2008中完成了我的第一个C#项目,现在它运行良好。 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. 此项目在同一台计算机上与我的SQL Server 2008 Adventureworks数据库进行交互。

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. 我知道HTML但不知道如何将.NET项目添加到网站,尤其是也使用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. 我首先右键单击项目并选择“转换为Web应用程序”,然后选择了我的站点的URL。 But then when I went to this URL, it still shows the original image. 但是当我访问此URL时,它仍然显示原始图像。

  1. In IIS create a website and point it to a directory that you want to put your website in. 在IIS中创建一个网站并将其指向您要将您的网站放入的目录。

  2. Make sure the website properties has the default document you want and the ASP.NET tab has the framework you want. 确保网站属性具有所需的默认文档,并且ASP.NET选项卡具有所需的框架。

  3. Use the menu in VS2008 to publish to this directory. 使用VS2008中的菜单发布到此目录。

  4. Change the connection string in your Web.Config to point to the correct database. 更改Web.Config中的连接字符串以指向正确的数据库。

Asp.Net has two types of projects: website and webapplication project . Asp.Net有两种类型的项目: 网站和Web应用程序项目

It looks like me that you are using the website project because you have the option to convert it the web application project. 看起来我正在使用网站项目,因为您可以选择将其转换为Web应用程序项目。 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. 右键单击您的项目,转到属性,转到“MsBuild选项”选项卡,您将看到一个Output文件夹,默认情况下,它应该有一个名为“PrecompiledWeb”的路径,这是您输出的位置,您需要将其部署到您的IIS目录。

you can't convert a windows application to a website, you have to built it from scratch. 你不能将Windows应用程序转换为网站,你必须从头开始构建它。

you can go to file -> new website -> then you choose ASP.NET website. 你可以去文件 - >新网站 - >然后你选择ASP.NET网站。

you might also use the sqldatasource and gridview controls, they help a lot. 你也可以使用sqldatasource和gridview控件,它们有很多帮助。

to run your website you can hit F5 or just right click your defalut.aspx page and select show in the browser! 要运行您的网站,您可以点击F5或右键单击您的defalut.aspx页面并在浏览器中选择显示!

check this for more information http://msdn.microsoft.com/en-us/library/41b1tfyt(VS.80).aspx hope it helps 检查这些以获取更多信息http://msdn.microsoft.com/en-us/library/41b1tfyt(VS.80).aspx希望它有所帮助

If your asking if you can move the location of the ASPNETDB away from the root of the project, yes, you can. 如果您询问是否可以将ASPNETDB的位置从项目的根目录移开,是的,您可以。 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. web.config中有数据库连接字符串节点,Visual Studio master.config文件中有master-default db config。 i think there is also a aspnetdbreg.exe or something like that to update the registration of this after you change its location. 我认为还有一个aspnetdbreg.exe或类似的东西,以便在更改其位置后更新此注册。

Personally, I use visual studio 2008 and my ASPNETDB is on my SQLServer express 2008 instance. 就个人而言,我使用visual studio 2008,我的ASPNETDB在我的SQLServer express 2008实例上。 Visit my blog for more info on this stuff. 访问我的博客,了解有关此内容的更多信息。

Since you are using IIS 7.0 what you need to do is find a place for your web application to reside (eg C:\\mywebapp). 由于您使用的是IIS 7.0,因此需要为Web应用程序找到一个位置(例如C:\\ mywebapp)。

Then open up IIS 7.0 Manager. 然后打开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 (eg if you want the url to be http://localhost/myawesomewebapplication/ from your local machine then type in myawesomewebapplication for the alias). 这将是您用来访问该站点的名称(例如,如果您希望该URL为本地计算机的http:// localhost / myawesomewebapplication / ,则输入myawesomewebapplication作为别名)。 Click the ellipsis (the ...) next to Physical Path and browse to the folder you copied your web files to (eg C:\\mywebapp). 单击Physical Path旁边的省略号(...)并浏览到您将Web文件复制到的文件夹(例如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. 假设没有错误,您现在应该能够浏览到http:// localhost /并且所有内容都应该是peachy。

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"; 如果要从Web应用程序访问数据库:1。创建新的ASP.NET Web应用程序(文件>新建>项目> Visual C# - Web)2。在项目属性(项目中的右键)中,转到“Web”选项卡“和”服务器“下;

Select the radio "Use Visual Studio Development Server", if you dont need to create an IIS virtual dir. 如果您不需要创建IIS虚拟目录,请选择“使用Visual Studio开发服务器”单选按钮。 Select the radio Use IIS Web server, if you need to create an IIS virtual dir. 如果需要创建IIS虚拟目录,请选择“使用IIS Web服务器”单选按钮。 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. 您可以创建一个类库(文件>新建>项目> Visual C# - Windows)来访问您的数据库,然后在您的Web应用程序中引用此程序集。 Just ask if you want that way. 只要问你是否想要这样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM