(Original release) How to Use C ++ to Develop ASP. NET? (. NET) (C ++/CLI) (ASP. NET) (C/C ++)

Source: Internet
Author: User

Abstract
Many people say that C ++ cannot develop ASP. net, ansi c ++ is true, but C ++/CLI is acceptable. In fact, any. net can be used to develop ASP. net, although Visual Studio 2005 is not supported, you can still use what you like if you have learned some tips. net was released ASP.. net.

Introduction
In Visual Studio. when net 2002 was released, I once heard from my colleagues that he used C ++ to access ASP. net, but at that time, I learned C #, but I still don't know C ++, so I didn't ask how he got it, c ++ has recently started. It has been found that Visual Studio 2005 can use C ++/CLI to develop a Windows form, but cannot develop ASP. net. On the network, only the Code project is merged to the Visual Studio. use managed C ++ ASP. net (Asp. net with managed C ++), but the pipeline method of managed C ++ and C ++/CLI is not the same, the original pipeline can not be compile, after a study, I finally found out how to use C ++/CLI to compile ASP.. net. In this article, I will explain step by step how to use C ++/CLI to Develop ASP. NET programs.

 

Step 1:
Create a web site

First, create a new web site.. Net does not support C ++. Therefore, when creating a web site, you must first select a statement.

 

Step 2:
Create a web form
Create a web form named helloworld. aspx. Do not select the desired place code in separate file. In this way, Visual Studio 2005 will place the event handler in the aspx handler to allow the Aspx. CPP saves the program for event declaration.

Step 3:
Add Gui
Use web form designer to make the following interfaces.

Step 4:
Modify helloworld. aspx
In the page ctictive section, divide Language = "C #" into, and add autoeventwireup = "true" inherits = "helloworld". helloword is the class name of C ++. <SCRIPT runat = "server"> </SCRIPT> must be partially divided.

1 <% @ page autoeventwireup = "true" inherits = "helloworld" %>
2
3 <! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4 <HTML xmlns = "http://www.w3.org/1999/xhtml">
5 6 <title> untitled page </title>
7 8 <body>
9 <Form ID = "form1" runat = "server">
10 <div>
11 using C ++/CLI in ASP. NET <br/>
12 <br/>
13 <asp: button id = "button1" runat = "server" onclick = "button#click" text = "button"/>
14 <asp: Label id = "label1" runat = "server" text = "label"> </ASP: Label> </div>
15 </form>
16 </body>
17 18


Step 5:
Create a C ++ Project
Select CLR in the left region. NET platform project, right-click the program CLR Empty Project, and remember not to select the program class library. This will lead to a lot of cases we don't need, in addition, we will not use Visual Studio 2005 for compile, and use command prompt for compile.

Step 6:
Create helloworld. aspx. cpp.
Select Code on the left and C ++ file (. cpp) on the right)

Step 7:
Add the C ++/CLI Program
C ++/CLI provides some additional charge for ansi c ++, so that it is different from the class in C ++, add ref modifier to the Managed class, and add ^ to the managed object. Most importantly, IDE supports intelliisense ASP. NET.

C ++/CLI/helloworld. aspx. cpp

1 # using <system. dll>
2 # using <mscorlib. dll>
3 # using <system. Web. dll>
4
5 using namespace system;
6 using namespace system: Web: Ui: webcontrols;
7
8 Public ref class helloworld: Public System: Web: Ui: Page {
9 protected:
10 button ^ button1;
11 label ^ label1;
12
13 public:
14 void button#click (Object ^ sender, eventargs ^ e ){
15 This-> label1-> text = "Hello World ";
16 return;
17}
18 };


Step 8:
Administrative Program
Use Visual Studio 2005 command prompt to initialize C ++/CLI.

Use the following routing method to export C ++/CLI.

1cl/CLR helloworld. aspx. CPP/link/dll/out: helloworld. dll

Step 9:
Deploymemt
Finally, you only need to put helloworld. aspx under c: \ Inetpub \ wwwroot \ and helloworld. dll under c: \ Inetpub \ wwwroot \ bin \ to complete deployment.

Conclusion 
Many people say that C ++ cannot develop ASP. net, Iso c ++ is true, but C ++/CLI is acceptable. In fact, any. net can be used to develop ASP. net, although Visual Studio 2005 is not supported, you can still use what you like if you have learned some tips. net was released ASP.. net.

(01/27/2007 updated)
This article is probably the first in the world to use C ++/CLI to Develop ASP. net, but back to reality, we should use C ++ to Develop ASP. net?

In practice, C ++/CLI develops ASP. net is really more difficult, and the speed of using C ++/CLI in the pipeline is not much faster than that in C, in practice, it is suggested that C # Be used to develop Web applications, and C ++ be used to develop system programs (Dynamic programs, kernel ..), the two are positioned differently.

If you are still reluctant to use C ++, the following is my suggestion:
Using a multi-dimensional Architecture
1. Presentation Layer: C # compiler is used for ASP. NET, which is mainly supported by Visual Studio 2005.
2. business Layer/data access layer, you can write c ++ program on OOP, STL, and GP.
3. Database: SQL Server or Oracle is used here.

This article mainly proves whether C ++ can write ASP. net, but there is no such thing as pushing. The main difference is that Visual Studio 2005 is not fully supported, which is inconvenient to start, if the next version of Microsoft allows Visual Studio to directly support C ++/CLI for ASP development. net. If you are a loyal believer in C ++, you can use C ++ to Develop ASP.. net.

In addition, C ++ needs to Develop ASP. net, uses C ++/CLI instead of Iso c ++. Although C ++/CLI contains all iso c ++, however, there are still some padding methods, such as changing pointer to ^ and reference to %... c ++/CLI is also an interesting topic.

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.