顯示具有 AzureCloudService 標籤的文章。 顯示所有文章
顯示具有 AzureCloudService 標籤的文章。 顯示所有文章

2021年7月7日 星期三

[研究] Azure 雲端服務(傳統) (CloudService)程式碼移植成單機 ASP.NET Web應用程式 (Web Application) 程式碼

[研究] Azure 雲端服務(傳統) (CloudService)程式碼移植成單機 ASP.NET Web應用程式 (Web Application) 程式碼

2021-07-21

* 建立一個 ASP.NET WebForm Web Application 方案,專案名稱建議用真正想要用的 (若先用 WebRole1 後面想再改名,會很複雜,有些設定似乎不是儲存在純文字檔案中)

* 把 AzureCouldService方案中 WebRole1 內容,拷貝到新方案的專案內,同檔案名稱者不取代,把他們加入專案中。(可以一次選多個目錄或檔案,但是不能包含已經在專案中的,否則「加入至專案」會灰色不能選。)

* 加入非 NuGet 安裝的參考。(可能有,或沒有,依個別專案不一定)

********************************************************************************

* Azure 使用的 using 註解掉,例如:

using Microsoft.WindowsAzure;   整個方案取代為   //using Microsoft.WindowsAzure;

using Microsoft.WindowsAzure.Diagnostics;  整個方案取代為   //Microsoft.WindowsAzure.Diagnostics;

using Microsoft.WindowsAzure.ServiceRuntime; 整個方案取代為  //Microsoft.WindowsAzure.ServiceRuntime

********************************************************************************

* 把 WebRole.cs 從專案排除


嚴重性 程式碼 說明 專案 檔案 行 隱藏項目狀態

錯誤 CS0115 'WebRole.OnStart()': 未找到任何合適的方法可覆寫 WebRole1 D:\Code\WebApplication1\WebApplication1\WebRole1\WebRole.cs 12 作用中

把 WebRole.cs 從專案排除

********************************************************************************

* 編譯 (Compile ) 或 重建 

逐一解決各種問題,NuGet 安裝所需要的套件。( 單機和雲端所需要的套件未必相同)

********************************************************************************

(完)

相關

[研究] Azure 雲端服務(傳統) (CloudService) 和 單機 ASP.NET Web應用程式程式碼比較https://shaurong.blogspot.com/2021/07/azure-cloudservice-aspnet-web.html

[研究][ASP.NET]錯誤 CS0115 'ApplicationSignInManager.CreateUserIdentityAsync(ApplicationUser)': 未找到任何合適的方法可覆寫
https://shaurong.blogspot.com/2021/07/aspnet-cs0115-applicationsigninmanagerc.html

[研究][ASP.NET]錯誤S1061, HttpContext, GetOwinContext,錯誤CS1061'HttpContext' 未包含 'GetOwinContext' 的定義
https://shaurong.blogspot.com/2021/07/s1061-httpcontext-getowincontextcs1061h.html

[研究][ASP.NET]錯誤 CS0234 命名空間 'Microsoft.AspNet' 中沒有類型或命名空間名稱 'FriendlyUrls' (是否遺漏了組件參考?)
https://shaurong.blogspot.com/2021/07/aspnet-cs0234-microsoftaspnet.html

[研究][ASP.NET]錯誤 CS0234 命名空間 'System.Web' 中沒有類型或命名空間名稱 'Optimization' (是否遺漏了組件參考)
https://shaurong.blogspot.com/2021/07/aspnet-cs0234-systemweb-optimization.html

[研究][ASP.NET]所建置之專案的處理器架構 "MSIL" 與參考 "SnsComServer_v3.4" 的處理器架構 "x86" 不相符。
https://shaurong.blogspot.com/2021/07/aspnet-msil-snscomserverv34-x86.html

[研究][ASP.NET]將檔案bin\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.xml 複製失敗。找不到檔案
https://shaurong.blogspot.com/2021/07/aspnet-binmicrosoftcodedomprovidersdotn.html

[研究][ASP.NET] 未指定 SMTP 主機
https://shaurong.blogspot.com/2021/07/aspnet-smtp.html

[研究][ASP.NET] No assembly found containing an OwinStartupAttribute
https://shaurong.blogspot.com/2021/07/aspnet-no-assembly-found-containing.html

[研究] Azure 雲端服務(傳統) (CloudService) 和 單機 ASP.NET Web應用程式程式碼比較

[研究] Azure  雲端服務(傳統) (CloudService) 和 單機 ASP.NET Web應用程式 (Web Application) 程式碼比較

AzureCloudService1

2021-07-06

為了把Azure  雲端服務(傳統) (CloudService) 移植到單機上,做點研究。

(下圖)Azure  雲端服務(傳統) (CloudService) 方案


********************************************************************************

(下圖)單機 ASP.NET Web應用程式 (Web Application) 方案

********************************************************************************
(下圖) 比較

Azure  雲端服務(傳統) (CloudService) 預設的方案名稱是「AzureCloudService1」 ,為了相近,敝人改名為「WebApplication1」

********************************************************************************
專案檔案放置

單機版 WebApplication1 方案的 WebApplication1 專案的 Default.aspx、Web.Config 等檔案,AzureCloudService 是放在 WebApplication1 方案的 WebRole1 專案。WebRole1 專案還多了 WebRole.cs 檔案。

********************************************************************************

Default.aspx 差異 (只列差異部分)

Default.aspx (AzureCloudService)

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebRole1.Default" %>

Default.aspx  (WebApplication)

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1.Default" %>

********************************************************************************

Default.aspx.cs 差異

Default.aspx.cs (AzureCloudService)

namespace WebRole1

Default.aspx.cs  (WebApplication)

namespace WebApplication1

********************************************************************************

Default.aspx.designer.cs 差異

Default.aspx.designer.cs (AzureCloudService)

namespace WebRole1

Default.aspx.designer.cs  (WebApplication)

namespace WebApplication1

********************************************************************************

AssemblyInfo.cs 差異

AssemblyInfo.cs (AzureCloudService)

[assembly: AssemblyTitle("WebRole1")]
[assembly: AssemblyProduct("WebRole1")]
[assembly: Guid("f668ccf8-bfd7-4995-ba0c-ac5ddd32b08a")]

AssemblyInfo.cs (WebApplication)

[assembly: AssemblyTitle("WebApplication1")]
[assembly: AssemblyProduct("WebApplication1")]
[assembly: Guid("3bae1aa8-b394-465e-86ea-b1183ae17d36")]

********************************************************************************

Web.Config比較 ( 單機版 Web Application 沒有 黃色區塊 )

<?xml version="1.0" encoding="utf-8"?>
<!--
  如需如何設定 ASP.NET 應用程式的詳細資訊,請前往
  https://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <system.diagnostics>
    <trace>
      <listeners>
        <add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=2.8.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
          name="AzureDiagnostics">
          <filter type="" />
        </add>
      </listeners>
    </trace>
  </system.diagnostics>
  <system.web>
    <compilation debug="true" targetFramework="4.8" />
    <httpRuntime targetFramework="4.8" />
  </system.web>
  <system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701" />
      <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
    </compilers>
  </system.codedom>
</configuration>


Web.Config 中連線字串比較

AzureCloudService

<add name="XXXWebConnectionString" connectionString="Data Source=xxx.database.windows.net;
Initial Catalog=資料庫名稱;User ID=資料庫帳號;Password=資料庫密碼;Encrypt=True"
providerName="System.Data.SqlClient" />

WebApplication

<add name="DefaultConnection" connectionString="Data Source=10.3.123.321;
Initial Catalog=資料庫名稱;Persist Security Info=True;User ID=資料庫帳號;Password=資料庫密碼" 
providerName="System.Data.SqlClient" />


(完)