【问题标题】:How to publish website form webapplication hosted in Azure?如何从托管在 Azure 中的 Web 应用程序发布网站?
【发布时间】:2015-04-27 01:44:15
【问题描述】:

需要在 Azure 中托管的网站发布表单 Web 应用程序的解决方案。

我尝试了以下代码,它创建了域,但我无法上传已发布的网站。

私有 HttpResponseMessage CreateWebsite(CreateSiteViewModel 站点) { var cert = X509Certificate.CreateFromCertFile(Server.MapPath(site.CertPath)); string uri = string.Format("https://management.core.windows.net/{0}/services/WebSpaces/{1}/sites/", site.Subscription, site.WebSpaceName);

        // A url which is looking for the right public key with 
        // the incomming https request

        var req = (HttpWebRequest)WebRequest.Create(uri);

        String dataToPost =string.Format(
            @"<Site xmlns=""http://schemas.microsoft.com/windowsazure"" xmlns:i=""http://www.w3.org/2001/XMLSchema-instance"">
              <HostNames xmlns:a=""http://schemas.microsoft.com/2003/10/Serialization/Arrays"">
                <a:string>{0}.azurewebsites.net</a:string>
              </HostNames>
              <Name>{0}</Name>
              <WebSpaceToCreate>
                <GeoRegion>{1}</GeoRegion>
                <Name>{2}</Name>
                <Plan>VirtualDedicatedPlan</Plan>
              </WebSpaceToCreate>
            </Site>", site.SiteName, site.WebSpaceGeo, site.WebSpaceName);

        req.Method = "POST";        // Post method
        //You can also use ContentType = "text/xml";

        // with the request
        req.UserAgent = "Fiddler";
        req.Headers.Add("x-ms-version", "2013-08-01");
        req.ClientCertificates.Add(cert);
        // Attaching the Certificate To the request

        // when you browse manually you get a dialogue box asking 
        // that whether you want to browse over a secure connection.
        // this line will suppress that message
        //(pragramatically saying ok to that message). 

        string postData = dataToPost;
        var encoding = new ASCIIEncoding();
        byte[] byte1 = encoding.GetBytes(postData);

        // Set the content length of the string being posted.
        req.ContentLength = byte1.Length;

        Stream newStream = req.GetRequestStream();

        newStream.Write(byte1, 0, byte1.Length);

        // Close the Stream object.
        newStream.Close();

        var rsp = (HttpWebResponse)req.GetResponse();

        var reader = new StreamReader(rsp.GetResponseStream());
        String retData = reader.ReadToEnd();

        req.GetRequestStream().Close();
        rsp.GetResponseStream().Close();

        return new HttpResponseMessage
        {
            StatusCode = rsp.StatusCode,
            Content = new StringContent(retData)
        };
    }

【问题讨论】:

    标签: azure


    【解决方案1】:

    我不完全确定您在这里尝试实现什么。但是,如果我理解正确,您想发布一个程序化网站。

    您无法使用 Azure 管理 API 执行此操作(以编程方式发布网站)。 Azure 管理 API 用于管理 Azure 服务和资源。网站内容本身绝不是 Azure 服务,也不是 Azure 资源。

    如果您想以编程方式将网站发布到 Azure 网站,我建议您深入阅读 How to deploy an Azure Web site

    从那里提到的内容来看,很容易实现自动化

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-11-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-12
      • 1970-01-01
      • 2017-05-17
      相关资源
      最近更新 更多