Dynamically create a website on azure

Source: Internet
Author: User

 

Dynamically create a website on azure

This article describes how to dynamically create a website on the deployed webrole. Of course, you can also use the role deployment package to create multiple websites or web virtual directories together, for this method, see my other article "Deploying webapps and WebServices in a webrole at the same time on windowsazure".

1. Upgrade webrole to administrator.

Append the following configuration in the servicedefinition. csdef file.

  <WebRole name="MvcWebRole1" vmsize="Small">    <Runtime executionContext="elevated"></Runtime>  </WebRole>

 

2,Port shielding on the firewall.

When we use conventional methods to deploy the site, our applications either use the same port with different hostnames or use the same IP address on different ports. On Azure, because azure only opens a fixed port in the firewall when deploying the file package (except for the port of Remote Desktop Connection, it is difficult to use different ports to create a website dynamically by using the same port and different hostnames. You can view which port is open on the Windows azure Management Portal.

3,Microsoft. Web. Administration assembly

In the code for creating a website, you must reference the Microsoft. Web. Administration assembly in the % WINDIR % \ system32 \ inetsrv directory. Because the GAC of azurehost does not contain the Assembly by default, you need to set the copy local attribute of the assembly to true.

 

4,Dynamic website creation code

String newwebsitepath = "your app path"; using (servermanager = new servermanager () {/* create application pool */applicationpool = servermanager. applicationpools. add ("myapplicationpool"); applicationpool. autostart = true; applicationpool. managedpipelinemode = managedpipelinemode. integrated; applicationpool. managedruntimeversion = "v4.0";/* create a web site */site = servermanager. sites. add ("mynewsite", "HTTP", "*: 80: www.mysite.com", newwebsitepath); site. applications [0]. applicationpoolname = "myapplicationpool"; site. serverautostart = true; servermanager. commitchanges ();}

5,Test the dynamically created website

This is also very simple. First, find the IP address of your deployed webrole in the window azure Management Portal, and then open the c: \ windows \ system32 \ drivers \ etc \ hosts file, add a record in the following format.

111.222.333.444 www.mysite.com

Then, enter www.mysite.com in your browser to see if you have created the site dynamically.

 

 

 

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.