mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-14 19:04:51 +08:00
Add version check for MVC Beta
--HG-- extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4043868
This commit is contained in:
@@ -1,12 +1,11 @@
|
|||||||
using System.Collections.Generic;
|
using System;
|
||||||
using System.Linq;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Reflection;
|
||||||
using System.Web;
|
using System.Web;
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
using System.Web.Routing;
|
using System.Web.Routing;
|
||||||
using Autofac;
|
|
||||||
using Autofac.Builder;
|
using Autofac.Builder;
|
||||||
using Autofac.Integration.Web;
|
|
||||||
using Autofac.Modules;
|
|
||||||
using Orchard.Environment;
|
using Orchard.Environment;
|
||||||
|
|
||||||
namespace Orchard.Web {
|
namespace Orchard.Web {
|
||||||
@@ -40,16 +39,61 @@ namespace Orchard.Web {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void Application_Start() {
|
protected void Application_Start() {
|
||||||
|
// This is temporary until MVC2 is officially released.
|
||||||
|
// We want to avoid running against an outdated preview installed in the GAC
|
||||||
|
CheckMvcVersion(new Version("2.0.41116.0")/*MVC2 Beta file version #*/);
|
||||||
RegisterRoutes(RouteTable.Routes);
|
RegisterRoutes(RouteTable.Routes);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
_host = OrchardStarter.CreateHost(MvcSingletons);
|
_host = OrchardStarter.CreateHost(MvcSingletons);
|
||||||
_host.Initialize();
|
_host.Initialize();
|
||||||
|
|
||||||
//TODO: what's the failed initialization story - IoC failure in app start can leave you with a zombie appdomain
|
//TODO: what's the failed initialization story - IoC failure in app start can leave you with a zombie appdomain
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void CheckMvcVersion(Version requiredVersion) {
|
||||||
|
Assembly loadedMvcAssembly = typeof(System.Web.Mvc.Controller).Assembly;
|
||||||
|
Version loadedMvcVersion = ReadAssemblyFileVersion(loadedMvcAssembly);
|
||||||
|
|
||||||
|
if (loadedMvcVersion != requiredVersion) {
|
||||||
|
string message;
|
||||||
|
if (loadedMvcAssembly.GlobalAssemblyCache) {
|
||||||
|
message = string.Format(
|
||||||
|
"Orchard has been deployed with a version of {0} that has a different file version ({1}) " +
|
||||||
|
"than the version installed in the GAC ({2}).\r\n" +
|
||||||
|
"This implies that Orchard will not be able to run properly in this machine configuration.\r\n" +
|
||||||
|
"Please un-install MVC from the GAC or install a more recent version.",
|
||||||
|
loadedMvcAssembly.GetName().Name,
|
||||||
|
loadedMvcVersion,
|
||||||
|
requiredVersion);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
message = string.Format(
|
||||||
|
"Orchard has been configured to run with a file version {1} of \"{0}\" " +
|
||||||
|
"but the version deployed with the application is {2}.\r\n" +
|
||||||
|
"This probably implies that Orchard is deployed with a newer version " +
|
||||||
|
"and the source code hasn't been updated accordingly.\r\n" +
|
||||||
|
"Update the Orchard.Web application source code (look for \"CheckMvcVersion\") to " +
|
||||||
|
"specify the correct file version number.\r\n",
|
||||||
|
loadedMvcAssembly.GetName().Name,
|
||||||
|
loadedMvcVersion,
|
||||||
|
requiredVersion);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new HttpException(500, message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Version ReadAssemblyFileVersion(Assembly assembly) {
|
||||||
|
object[] attributes = assembly.GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true);
|
||||||
|
if (attributes == null || attributes.Length != 1) {
|
||||||
|
string message = string.Format("Assembly \"{0}\" doesn't have a \"{1}\" attribute",
|
||||||
|
assembly.GetName().Name, typeof(AssemblyFileVersionAttribute).FullName);
|
||||||
|
throw new FileLoadException(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
var attribute = (AssemblyFileVersionAttribute)attributes[0];
|
||||||
|
return new Version(attribute.Version);
|
||||||
|
}
|
||||||
|
|
||||||
protected void Application_EndRequest() {
|
protected void Application_EndRequest() {
|
||||||
_host.EndRequest();
|
_host.EndRequest();
|
||||||
|
@@ -62,6 +62,7 @@
|
|||||||
<Reference Include="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
<Reference Include="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||||
<SpecificVersion>False</SpecificVersion>
|
<SpecificVersion>False</SpecificVersion>
|
||||||
<HintPath>..\..\lib\aspnetmvc\System.Web.Mvc.dll</HintPath>
|
<HintPath>..\..\lib\aspnetmvc\System.Web.Mvc.dll</HintPath>
|
||||||
|
<Private>True</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="System.Xml.Linq">
|
<Reference Include="System.Xml.Linq">
|
||||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||||
|
Reference in New Issue
Block a user