2012年11月30日

[Azure]在WebRole使用HTTPS Endpoint

  1. 打開VS,到Role –> Property->Certificates,加入一張已經存在Personal Certificate Store的憑證。(可以使用Self-signed,這邊就不針對如何產生憑證多做說明了) 

    image

  2. 到Role –> Property –> Endpoints,加入一個HTTPS Endpoint

    image

  3. 把憑證(PFX檔)上傳到Azure,必須要先建立好Cloud Service後,從Cloud Service的設定頁面上傳。

    image

  4. 接下來只要把程式佈署上去就可以啦。

2012年11月29日

[Azure]一些ACS相關的問題 (1)

  1. 使用VS2012使用ACS v2.0驗證時,透過Identity and Security…設定完ACS Namespace之後,在本機跑都很正常,但是放到雲端上就一堆錯誤。這問題主要是因為目前使用Identity and Security時,他會設定使用.Net Framework 4.5版本的assembly,但是現在除非我們在cscfg中去指定osfamily=”3”,使用Windows 2012 Server才會有.Net 4.5支援,否則的話只能使用.Net Framework 4.0。

因此我們必須手動修改相關設定,讓程式使用.Net framework 4.0。

首先設定完ACS後,打開VS2012,確定Target Framework是4.0

image

接下來要修改web.config,首先要將configuration section預設使用的<security.identityModel>與<security.identityModel.services>註解掉,新增以下這一行:

<section name="microsoft.identityModel" type="Microsoft.IdentityModel.Configuration.MicrosoftIdentityModelSection, Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

接著把下面的<security.identityModel>與<security.identityModel.services>整段mark掉,換成下面這一段:

<microsoft.identityModel>
  <service>
    <securityTokenHandlers>
      <securityTokenHandlerConfiguration>
        <audienceUris>
          <add value=http://{your URL}/ />
        </audienceUris>
        <issuerNameRegistry type="Microsoft.IdentityModel.Tokens.ConfigurationBasedIssuerNameRegistry, Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
          <trustedIssuers>
            <add thumbprint="C75956CC7E0B8F90ED52A3AEF970465CD630F0E0" name=https://{ACS Namespace}.accesscontrol.windows.net/ />
          </trustedIssuers>
        </issuerNameRegistry>
      </securityTokenHandlerConfiguration>
    </securityTokenHandlers>
    <certificateValidation certificateValidationMode="None" />
    <federatedAuthentication>
      <cookieHandler requireSsl="false" />
      <wsFederation passiveRedirectEnabled="true" issuer=https://{ACS Namespace}.accesscontrol.windows.net/v2/wsfederation realm=http://{your URL}/ reply=http://{your URL}/” requireHttps="false" />
    </federatedAuthentication>
  </service>
</microsoft.identityModel>

然後設定runtime validation mode

<httpRuntime requestValidationMode="2.0" />

修改<system.webServer>如下:

<system.webServer>
  <modules>
    <!--<add name="WSFederationAuthenticationModule" type="System.IdentityModel.Services.WSFederationAuthenticationModule, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" preCondition="managedHandler" />
    <add name="SessionAuthenticationModule" type="System.IdentityModel.Services.SessionAuthenticationModule, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" preCondition="managedHandler" />-->
    <add name="WSFederationAuthenticationModule" type="Microsoft.IdentityModel.Web.WSFederationAuthenticationModule, Microsoft.IdentityModel" preCondition="managedHandler" />
    <add name="SessionAuthenticationModule" type="Microsoft.IdentityModel.Web.SessionAuthenticationModule, Microsoft.IdentityModel" preCondition="managedHandler" />

  </modules>

2012年11月28日

[Azure]Validation Errors: Total requested resources are too large for the specified VM size

While deploying my cloud project with all roles set to XS size VM, I got this error message stating my resource is too large for specified VM size.

As VM of XS size only have 20G C Drive, most likely I specified a local storage larger then 20G. So I checked my Role settings and found when creating cache worker role, the VM size defaults to Small, and diagnostic storage was set to 20G by default, hence exceed the size limit.

so the fix is to lower local diagnostic storage size.

image

2012年11月21日

[Azure]Tips to setup Hosting Solution Services

Update – 2012/11/29

這是安裝Microsoft Hosting Solution Services 的血淚史。

1.SQL Server Collation必須設定為SQL_Latin1_General_CP1_CI_AS,如果作業系統不是英文版,又是透過Web Platform Installer來裝SQL Express的話,安裝過程中沒辦法修改,可以參考這一篇的方式修改(我沒實測過)。

2.MySQL一定要裝,雖然安裝步驟上寫SQL Server or MySQL,但實測如果沒裝MySQL的話,Configure時會出現Invalid Object admin.UserCredential的錯誤。

3.每台機器上都要Enable Remote Administration Firewall Exception,用以下指令啟用:

netsh firewall set service remoteadmin enable

但是雖然啟用了上述的防火牆例外,我在安裝時還是遇到一堆因為防火牆導致安裝設定失敗的狀況(主要是RPC Fail),所以,安裝時就痛快地先關掉防火牆吧。

4.設定完SitesController後,就可以利用SitesController上的IIS Manager –> Web Farm來監控各個伺服器的設定進度。

5.在設定FrontEnd時,一直出現無法安裝某些特定元件的錯誤,所以直接RDP到FrontEnd機器,透過Web Platform Installer直接下載那些安裝失敗的元件,然後重開機,接著從Management Portal上把這台機器移除後重新加入即可。(講得很簡單,實際上這個動作可能會重複好幾次)

6.同上,安裝SitesWWS時,需要先到SitesWWS上手動安裝Web Farm Framework Agent。

7.SitesWWS, Add CloudAdmin to Administrators Group

8.SitesWWS, Install Web Deploy 3.0

9.SitesRESTAPI, create CloudAdmin account

10.最重要的一件事情是,在Controller上設定資料庫位置以及各個管理員帳號密碼時,一定要注意不要key錯了! (不然就會血尿很多天…)

11.安裝設定完成後,在使用Web Gallery建立網站時,可能會遇到無法下載Web Gallery的問題。我做了兩個改變解決這件事,但是目前不確定哪個改變解決問題:

1.把SitesMgmtPortal中IIS上的MgmtSvc-WebAppGallery的.Net Globalization裡的Culture與UI Culture都改為United State

2.把所有機器的控制台 –> 地區選項裡的時間格式改為yyyy-MM-dd HH:mm: ss

12.到SitesPublisher上,確定Web Management Service、Web Farm Agent Service和Web Deployment Agent Service是以啟動並且是自動執行。

12.如果遇到Unable to connect to remote server的錯誤,到SitesPublisher上,把WebFarm Agent Service重啟,然後把Dynamic WAS Service重啟幾次,應該可以解掉這個問題。

2012年11月16日

[Azure]查詢Azure SQL DB的使用量

連到要查詢的資料庫,然後執行下列命令。

select
      sum(reserved_page_count) * 8.0 / 1024
from
      sys.dm_db_partition_stats
GO

結果的單位是MB

2012年11月7日

[Azure]用REST API列出Storage Account下的Container

照著MSDN試了半天,終於發現順序還是很重要的。

假設我的Storage Account是slakchiprod,則我的request URL要是http:/slakchiprod.blob.core.windows.net/?comp=list

然後以下面這段程式碼來取得slakchiprod下的所有container。

            var utcTime = DateTime.UtcNow.ToString("R");
var xmsversion = "2011-08-18";
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(new Uri(URL));
req.Method = "GET";
//下面這兩個Header的順序不能改...
req.Headers["x-ms-version"] = xmsversion;
req.Headers["x-ms-date"] = utcTime;
string stringToSign = "GET\n" +
"\n" + /*Content-Encoding*/
"\n" + /*Content-Language*/
"\n" + /*Content-Length*/
"\n" + /*Content-MD5*/
"\n" + /*Content-Type*/
"\n" + /*Date*/
"\n" + /*If-Modified-Since */
"\n" + /*If-Match*/
"\n" + /*If-None-Match*/
"\n" + /*If-Unmodified-Since*/
"\n" + /*Range*/
"x-ms-date:{0}\n" +
"x-ms-version:{1}\n" +
"/{2}/\n" + //URL
"{3}"; //Param
stringToSign = string.Format(stringToSign,
utcTime,
xmsversion,
storageAcct,/*slakchiprod*/
"comp:list");

HMACSHA256 crypt = newHMACSHA256(Convert.FromBase64String(key));
var buffer = crypt.ComputeHash(.UTF8.GetBytes(stringToSign));
var result = Convert.ToBase64String(buffer);
req.Headers["Authorization"] = "SharedKey " + string.Format("{0}:{1}", storageAcct, result);

req.GetResponse();//取得回應

2012年11月2日

[Azure]幾個上傳VHD的方式比較 (1)

剛好有客戶在做類似的東西,所以就順便比較看看。

首先一定要先確定在Local的VHD有開啟遠端桌面連線。

image

1.csupload –AddDisk, 沒有加-OS選項

目標VHD : Win XP 9GB Dynamic Disk, 沒有做過sysprep。

來不及抓圖了,這時,VHD檔案會被當作OS Disk,列在Virtual Machine->Disk中,沒有辦法用這個Disk建立VM。

2.csupload –AddDisk, 加了 –OS選項

目標VHD : Win XP 9GB Dynamic Disk, 沒有做過sysprep。

image

進入Portal、Virtual Machines、Create New Virtual Machine、My Disks可以看到剛剛上傳的VHD。可以用它來建立VM。

檢查Storage,看得到這個VHD,大小是127G。testadddisk1是我指定的label name。

image

用這個VHD來建立VM。

image

3.csupload –Add-Disk, 加-OS

目標VHD : Win 2008 30G Fixed Disk, 沒有做過sysprep。

image

可以在Virtual Machines、My Disks中找到她。

image

可以以此Disk建立VM。

image

Blog Archive

About Me