C#-vs Publishing Web site-preparing a Web site for publishing

Source: Internet
Author: User

To deploy a Web site project by using the Publish Web site tool
    • Prepare the Web site source file
    • Generate a publish file in VS
    • Configure IIS
. NET Framework 4Other versions
    • Visual Studio 2008
    • Visual Studio 2005

Steps you through how to compile a Web site project by using the Publish Web Site tool of Visual Studio, and then copy the output to the specified location.

If you are deploying a Web site project to a server, you can use the Publish Web site tool that is included with Visual Studio. The Publish Web site tool pre-compiles the pages and code in the Web site, and then writes the compiler output to the specified folder. you can then copy the output to the target Web server and run the application from the target Web server.

Attention

The Publish Web Site tool is not available in Visual Web Developer Express Edition.

If you are deploying to production, you may want to prevent the production site from responding to page requests during the deployment process to help avoid errors that may result when the changes are in progress. at the same time, you may want to ensure that the application domain is not recycled more than once during deployment. these tasks are not covered in this walkthrough. For more information, see How to: Prepare your WEB project for deployment.

Attention

This topic applies only to Web site projects. For information about the differences between Web application projects and Web site projects, see Web Application Projects and Web site projects.

System Prerequisites

To complete this walkthrough, you need to:

    • Visual Studio.

      Attention

      This walkthrough assumes that you selected the Web Development Settings collection The first time that you started Visual Studio. For more information, see How to: Select WEB development environment settings.

    • can access Microsoft Internet Information Services (IIS) so that you can test the results of published Web site projects. in this walkthrough, you assume that IIS is already running on your own computer. or you can use any instance of IIS, but you need to have permission to create a virtual directory for it.

Prepare the Web site source file

If you have already created a Web site project in Visual Studio (for example, by completing Walkthrough: Creating a Basic Web page in Visual Studio), you can use the project and go to the next section. Otherwise, create a new Web site project. in this walkthrough, you will create a file system Web site.

Create a file system Web site
    1. Open Visual Studio.

    2. On the File menu, click New Web site.

      Displays the new Web Site dialog box.

    3. Under Installed templates, click Visual Basic or Visual C #, and then select the ASP. NET empty Web site.

    4. In the Web location box, select File System, and then enter the name of the folder where you want to save the Web page.

      For example, type the folder name "C:\WebSites".

    5. Click OK.

      Visual Studio will create a Web site project that contains only one Web. config file.

In this walkthrough, you will create a Web page that contains some controls. You will also create a class file that will be used in the Web page. creating a Web page and a separate class will let you know how the publishing process compiles the content of the Web site.

You will first create a new page, and then add a button and label to the page.

Create a page and add a control
    1. under "Installed Templates", select the Preferred programming language, then click Web Forms.

    2. in the Name box, type SamplePage.aspx.

    3. click "Add".

    4. switch to Design view.

Next you will create a source code for a simple class that contains only one property. you will use the class in the Code of the page.

Create Class
  1. In Solution Explorer, right-click the name of the Web site project, point to add ASP. Net Folder, and then click App_Code.

    In Solution Explorer, a new folder named App_Code appears in the application. The App_Code folder is a reserved ASP. NET Application Folder. For more information, see ASP. NET Web project folder structure.

  2. Right click the App_Code folder, and then click Add New Item.

  3. Under Installed templates, click the language that you prefer to use, and then click Class.

  4. In the Name box, type TestClass.

  5. Click Add.

    Visual Studio creates a skeleton class file in the specified programming language.

  6. Create a property named TestProperty.

    When finished, the complete class file will resemble the following:

    C#VB replication
    Using System;publicclass testclass{public    TestClass () {}    privatestring TestPropertyValue;    Publicstring testproperty    {        get{return testpropertyvalue;}        set{TestPropertyValue = value;}}     }

You can now use the class in the page. Note that you do not have to compile the class before you use it.

Use this class in a page
    1. Open "samplepage.aspx" and Switch to "design" view.

    2. Double-click the Button control to create a click handler for the control.

    3. In the Click handler, create an instance of TestClass (created in the previous procedure), assign a value to the TestProperty property, and then display the TestProperty value in the Label control.

      The complete code looks something like this:

      C#VB replication
      Protectedvoid Button1_Click (object sender, EventArgs e) {    TestClass TestClass = new TestClass ();    Testclass.testproperty = "Hello";    Label1.Text = Testclass.testproperty;}
Test Web site

Sites can be tested before the site is published to ensure that the site works as expected.

Test Web site
    1. Open the SamplePage.aspx page.

    2. Press CTRL+F5.

      The page appears in the browser.

    3. Click button to make sure that the text appears in the Label control.

    4. Close the browser.

C#-vs Publishing Web site-preparing a Web site for publishing

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.