廣告:
舊環(huán)境:asp.net mvc 2.0 asp.net 3.5 sp1 visual studio 2010
新環(huán)境:asp.net mvc 5.2.7 asp.net 4.8 visual studio 2022
類庫可以直接升級(jí),無須特殊配置
1 準(zhǔn)備工作
a 模板方案建立:新建解決方案,新建web mvc應(yīng)用程序項(xiàng)目空(目標(biāo) asp.net 4.8,添加文件夾和核心引用都不要選,高級(jí) https配置也不要選)保存。此解決方案文件可作為參考。
b 正式升級(jí),打開舊的解決方案,能加載的類庫直接升級(jí)到目標(biāo)asp.net 4.8(由目標(biāo)asp.net 3.5 sp1改成目標(biāo) asp.net 4.8),不能加載的項(xiàng)目先卸掉。
打開我的電腦,把原先舊web mvc項(xiàng)目目錄改名 ;
visual studio 2022打開的解決方案里面,新建web mvc項(xiàng)目,名稱與舊的mvc項(xiàng)目同名,程序集名稱和默認(rèn)命名空間也改成原先命名空間名稱(一般與舊web mvc項(xiàng)目名稱同名)。
2 復(fù)制(最好剪切,防止漏掉文件)改名目錄項(xiàng)目文件到新項(xiàng)目目錄,包含到新web mvc項(xiàng)目中。
3 引用 system.web.mvc 5.2.7 復(fù)制到本地
引用 Newtonsoft.Json 13.0.1 復(fù)制到本地
引用 System.Runtime.Serialization
引用 System.Web.WebPages.Razor.dll 3.0.0 復(fù)制到本地
引用 Microsoft.Web.Infrastructure.dll 1.0 (Master控件需要)
引用其他層原先的類庫,并按原先順序配置依賴項(xiàng) 如:RouteDebug.dll Gma.QrCodeNet.Encoding.Net35.dll
更新 MvcViewEngine類 引用的類庫 system.web.mvc 為新版本 5.2.7
Mvcmode類去掉 System.xml引用
Mvcbll類去掉 System.Window.Form引用
Mvccom類去掉 Microsoft.mshtml
注意:web.config <namespaces></namespaces>引用的命名空間,必須要復(fù)制到bin目錄下面,也就是引用時(shí)開啟復(fù)制到本地選項(xiàng)。
4 配置web.config 復(fù)制舊的必要字段到新的 web.config
如:
<system.web> <compilation debug="true" targetFramework="4.8"/> <pages> <namespaces> <!--<add namespace="System.Web.Helpers" /> <add namespace="System.Web.Mvc.Ajax"/> <add namespace="System.Web.Routing"/>--> <add namespace="System.Web.Mvc"/> <add namespace="System.Web.Mvc.Html"/> <!--<add namespace="System.Web.WebPages"/> <add namespace="System.Web.WebPages.Razor"/>--> <add namespace="System.Collections.Generic"/> <add namespace="System.Data"/> <add namespace="FeiShareLibrary"/> </namespaces> </pages> </system.web>
集成管道模式需要加:
<system.webServer> <validation validateIntegratedModeConfiguration="false" /> <modules runAllManagedModulesForAllRequests="true"> <add name="HttpImageModule" type="Mvccom.HttpImageModule,Mvccom"/> </modules> <remove name="ExtensionlessUrlHandler-Integrated-4.0" /> <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" /> <!--以下為經(jīng)典模式用--> <add name="mvc64" path="*" verb="*" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="None" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" /> </system.webServer>
5 如果有webform頁面,相應(yīng)目錄web.config需要配置
<?xml version="1.0" encoding="utf-8"?> <configuration> <appSettings> <add key="ValidationSettings:UnobtrusiveValidationMode" value="None" /> </appSettings> </configuration>
6 設(shè)置嵌入的資源:
AssemblyInfo.cs 添加 :
[assembly: System.Web.UI.WebResource("Mvcb2b.Scripts.class.js", "application/x-javascript")]
7 WebResource.axd 404錯(cuò)誤,提示:無效的 Webresource 請(qǐng)求
ASP .Net 3.5應(yīng)用程序升級(jí)到.NET 4.8提示:webresource.axd 404 錯(cuò)誤 ,參照上一條 設(shè)置嵌入的資源
8. 提示:訪問aspx文件提示分析器錯(cuò)誤消息: 未能加載類型“Mvcb2b.editors.Uphtml”
原因:web應(yīng)用程序?qū)?yīng)相應(yīng)webform文件可能沒有包含到項(xiàng)目當(dāng)中。應(yīng)該包括在項(xiàng)目中。
9 更改文件后,需要先生成(bin下有文件) 模板頁面:ViewData 提示才不會(huì)出錯(cuò)
10 工具---Nuget包管理器---管理解決方案的Nuget程序包刪除 Microsoft.CodeDom.Providers.DotNetCompilerPlatform 包 (舊項(xiàng)目沒有用到此項(xiàng))
PM> Install-Package Microsoft.CodeDom.Providers.DotNetCompilerPlatform (安裝)
Uninstall-Package Microsoft.CodeDom.Providers.DotNetCompilerPlatform (刪除)
11 asp.net 4.8相關(guān)的類庫或者項(xiàng)目 --應(yīng)用程序 設(shè)置那里 把自動(dòng)生成綁定重定向 前面的勾去掉。
12 packages.config 文件是 管理Nuget程序包的配置文件,有它則可以讀到當(dāng)前 Nuget程序包信息?梢詣h除不影響程序運(yùn)行。
13 解決方案--屬性--調(diào)試源文件刪除相關(guān)選項(xiàng)內(nèi)容
14 cooke 設(shè)置加 Cookiesname.SameSite = SameSiteMode.Lax; 不然 ajax和iframe頁面可能不能設(shè)置 cookie
HttpContext.Current.Response.Cookies[CookieName].SameSite = SameSiteMode.Lax; Cookiesname.SameSite= SameSiteMode.Lax;
15 升級(jí)后的項(xiàng)目調(diào)試時(shí),要先把默認(rèn)瀏覽器打開
16 IIS集成模式404頁面不經(jīng)過Application_Error,可在web.config加如下設(shè)置:
<httpErrors errorMode="DetailedLocalOnly" existingResponse="PassThrough"> <!--Custom DetailedLocalOnly Detailed --> <remove statusCode="404" subStatusCode="-1" /> <!--<error statusCode="404" prefixLanguageFilePath="" path="~/Main/Notfound" responseMode="ExecuteURL" />--> </httpErrors>
17 模板下面web.config 也需要更新
項(xiàng)目發(fā)布后更新文件:
1 bin目錄下面文件全部替換
2 web.config替換
3 webform程序目錄下面增加或者替換 web.config
4 模板頁面 themes/default/目錄下面 web.config替換
5 config/53bknet.config 添加字段
常見錯(cuò)誤參考:
檢測(cè)到在集成的托管管道模式下不適用的 ASP.NET 設(shè)置-HTTP Error 500.22
http://www.asiacable.com.cn/news/detail/v13174.html
訪問aspx文件提示分析器錯(cuò)誤消息: 未能加載類型“Mvcb2b.editors.Uphtml
http://www.asiacable.com.cn/news/detail/v13173.html
IIs經(jīng)典模式服務(wù)器上的“ISAPI 和 CGI 限制”列表設(shè)置,無法提供您請(qǐng)求的頁面
http://www.asiacable.com.cn/news/detail/v13176.html
以下為更新內(nèi)容:
1 Ipcachebll
if (nIndexFDot == -1) //第一個(gè)
return true;
2 Fun.IsNum(String str) 更改
3 Fun.GetRealIP() 更改
ip = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString(); if (ip != "") { //ip = ip.Split(',')[0]; //獲得代理ip,多個(gè)ip,最近一個(gè)為真實(shí)ip(但是可以偽造) string[] splitter = { "," }; string[] IP_Array = ip.Split(splitter, System.StringSplitOptions.None); int LatestItem = IP_Array.Length - 1; ip = IP_Array[LatestItem]; }
4 System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5")
換成:
DESEncrypt.NewMD5(sKey, "md5") NewMD5(sKey, "md5") public static string NewMD5(string strData,string md5str) { string strResult = ""; using (var md5 = MD5.Create()) { var result = md5.ComputeHash(Encoding.UTF8.GetBytes(strData)); strResult = BitConverter.ToString(result); strResult= strResult.Replace("-", "").ToUpper(); } return strResult; }
5 控件id更新 ctl00開頭webform里面control控件生成的id 去掉 ctl00_ /admin 目錄下面文件需要全部更新
6 檢查控件的緩存
廣告: