首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> .NET 網頁程式設計 >> ASP.NET 基礎 >> 關於ASP.NET

ASP.NET 4.0 升級 4.5 關鍵步驟:httpRuntime targetFramework 與 machineKey 相容性設定

     編輯:關於ASP.NET

單純修改專案 Target Framework 與 <compilation targetFramework="4.5"/> **不足以** 完成 ASP.NET 4.5 升級,必須同時設定 httpRuntime。

必要設定

<system.web>
  <httpRuntime targetFramework="4.5" />
  <compilation targetFramework="4.5" />
</system.web>

升級後必須注意的兩大陷阱

1. machineKey 相容性模式

ASP.NET 4.5 預設 compatibilityMode="Framework45",加解密演算法變更。若**未同步升級所有應用程式**,表單驗證票證將無法跨應用程式解密。需依舊版本調整:

<machineKey compatibilityMode="Framework20SP1" />  <!-- .NET 2.0 SP1 相容 -->
<machineKey compatibilityMode="Framework20SP2" />  <!-- .NET 2.0 SP2 相容 -->

2. WebForms 驗證控制項 UnobtrusiveValidationMode

升級後使用 <asp:RequiredFieldValidator> 等控制項會拋出:
WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping for 'jquery'.

解決:在 <appSettings> 加入:

<add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />

或正確註冊 jQuery ScriptResourceMapping。

總結

升級核心在於 httpRuntime targetFramework,並務必處理跨應用程式驗證相容與驗證控制項行為變更。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved