廣告:
先新建一個(gè)空的asp.net mvc 4.0web應(yīng)用程序,然后備份老項(xiàng)目web.config。復(fù)制新的web.config到舊的項(xiàng)目。另外把舊的應(yīng)用程序項(xiàng)目生成目標(biāo)改為 asp.net 4.0
1 view里面config變化更新
page字節(jié):
<pages
validateRequest="false"
pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<controls>
<add assembly="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
</controls>
</pages>
2 根目錄下面web.config變化更新
添加: appSettings、 connectionStrings
添加: namespaces
<add namespace="System.Collections.Generic"/>
<add namespace="System.Data"/>
<add namespace="FeiShareLibrary"/>
添加:httpModules
添加:globalization
改動(dòng):pages
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"> 改成下面 <pages>
不然提示找不到 System.Web.Mvc
C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 4\Packages\Microsoft.AspNet.Mvc.4.0.20710.0\lib\net40\System.Web.Mvc.dll
C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 4\Assemblies\System.Web.Mvc.dll
常見(jiàn)錯(cuò)誤:
編譯錯(cuò)誤
說(shuō)明: 在編譯向該請(qǐng)求提供服務(wù)所需資源的過(guò)程中出現(xiàn)錯(cuò)誤。請(qǐng)檢查下列特定錯(cuò)誤詳細(xì)信息并適當(dāng)?shù)匦薷脑创a。
編譯器錯(cuò)誤消息: CS0234: 命名空間“System.Web”中不存在類型或命名空間名稱“Mvc”(是否缺少程序集引用?)
源錯(cuò)誤:
行 31: <namespaces>
行 32: <!--<add namespace="System.Web.Helpers" />-->
行 33: <add namespace="System.Web.Mvc" />
行 34: <add namespace="System.Web.Mvc.Ajax" />
行 35: <add namespace="System.Web.Mvc.Html" />
源文件: e:\aspnet2.0\53BK公司網(wǎng)站-net-家里\Mvcb2b\Web.config 行: 33
解決辦法:引用時(shí)復(fù)制到本地
ViewEngines.Engines.Add(engine);
用戶代碼未處理 System.ArrayTypeMismatchException
HResult=-2146233085
Message=嘗試訪問(wèn)類型與數(shù)組不兼容的元素。
Source=mscorlib
StackTrace:
在 System.Collections.Generic.List`1.Insert(Int32 index, T item)
在 System.Collections.ObjectModel.Collection`1.InsertItem(Int32 index, T item)
在 System.Web.Mvc.ViewEngineCollection.InsertItem(Int32 index, IViewEngine item)
在 System.Collections.ObjectModel.Collection`1.Add(T item)
在 Mvcb2b.MvcApplication.Application_Start() 位置 E:\aspnet2.0\53BK公司網(wǎng)站-net-家里\Mvcb2b\Global.asax.cs:行號(hào) 247
InnerException:
解決辦法,把a(bǔ)sp.net mvc相關(guān)的類庫(kù)目標(biāo)改為 asp.net 4.0
3 asp.net mvc4.0 控件中參數(shù)緩存變化
左邊控件
[OutputCache(Duration = 2000, VaryByParam = "none",VaryByCustom = "Crawler")]
改為 [OutputCache(Duration = 2000, VaryByParam = "id;nowname",VaryByCustom = "Crawler")]
如: [OutputCache(Duration = 9526, VaryByParam = "classid;parentid;urlname;nowname", VaryByCustom = "Crawler")]
public ActionResult Productleft(string classid,string parentid,string urlname,string nowname)
引用:<%--左邊內(nèi)容--%>
<%Html.RenderAction("Productleft", "Userinc", new { classid = Model.Id, parentid = Model.Parentid, urlname = ViewData["urlname"], nowname = Model.Classname }); %>
頂部控件:
[OutputCache(Duration = 19526, VaryByParam = "*", VaryByCustom = "Crawler")]
/* 調(diào)用了 Reqeust.Url 所以需要用* */
public ActionResult Top(string ishome)
引用: <%-- 頂部--%>
<%Html.RenderAction("Top", "Userinc"); %>
廣告: