ASP MVC2部署到IIS 7时出错

时间:2011-04-26 02:23:13

标签: asp.net asp.net-mvc-2 deployment iis-7

将应用程序部署到IIS7服务器之后,它在开始时似乎很好并且可以显示登录页面。但是在用户输入用户名和密码后,我必须使用DB连接对用户进行身份验证。此时,它显示错误(附加)。我猜错误是由EntityFramwork加载DB数据时的反射引起的。

我的服务器已经安装.net framework 3.5 sp1。

另一方面,我尝试过另一台服务器。如果已经为VS2008安装了服务器VS2008和MVC2,则该服务器可以在IIS7中正确运​​行该应用程序。

我的目标是在仅具有.net framework 3.5的IIS7服务器上运行该应用程序。

请帮我解决这个问题。

错误数据:

Server Error in '/FDDV_demo' Application.
--------------------------------------------------------------------------------

Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Stack Trace: 


[ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.]
   System.Reflection.Module._GetTypesInternal(StackCrawlMark& stackMark) +0
   System.Reflection.Assembly.GetTypes() +111
   System.Data.Metadata.Edm.AssemblyCacheEntry.LoadTypesFromAssembly(LoadingContext context) +28
   System.Data.Metadata.Edm.AssemblyCacheEntry.InternalLoadAssemblyFromCache(LoadingContext context) +290
   System.Data.Metadata.Edm.AssemblyCacheEntry.LoadAssemblyFromCache(Assembly assembly, Boolean loadReferencedAssemblies, Dictionary`2 knownAssemblies, Dictionary`2& typesInLoading, List`1& errors) +137
   System.Data.Metadata.Edm.ObjectItemCollection.LoadAssemblyFromCache(ObjectItemCollection objectItemCollection, Assembly assembly, Boolean loadReferencedAssemblies) +284
   System.Data.Metadata.Edm.ObjectItemCollection.LoadAssemblyForType(Type type) +33
   System.Data.Metadata.Edm.MetadataWorkspace.LoadAssemblyForType(Type type, Assembly callingAssembly) +80
   System.Data.Objects.ObjectContext.CreateQuery(String queryString, ObjectParameter[] parameters) +106
   FDDV.Models.DBEntities.get_user_master() +113
   FDDV.Controllers.HomeController.validateUser(String userid, String password) +254
   FDDV.Controllers.HomeController.LogOn(LogOnModel model, String returnUrl) +134
   lambda_method(ExecutionScope , ControllerBase , Object[] ) +136
   System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +17
   System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +178
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +24
   System.Web.Mvc.<>c__DisplayClassd.<InvokeActionMethodWithFilters>b__a() +53
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +258
   System.Web.Mvc.<>c__DisplayClassf.<InvokeActionMethodWithFilters>b__c() +20
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +193
   System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +316
   System.Web.Mvc.Controller.ExecuteCore() +104
   System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +36
   System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +7
   System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__4() +34
   System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +21
   System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +12
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +53
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +43
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +7
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8682542
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155




--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.4952; ASP.NET Version:2.0.50727.4955 

2 个答案:

答案 0 :(得分:1)

我终于解决了这个问题。主要原因是该项目错过了一些装配参考。我将以下代码添加到login函数以找出反射类型加载异常。再次感谢大家的帮助

try{
    //Do your work

        } 
    catch (Exception ex)
                        {

                            ReflectionTypeLoadException exception = ex as ReflectionTypeLoadException;

                            if (exception == null)
                                System.IO.File.AppendAllText("C:\\TestLog.txt", "Not a ReflectionTypeLoadException ex.");
                            else
                            {
                                foreach (Exception loaderException in exception.LoaderExceptions)
                                {
                                    System.IO.File.AppendAllText("C:\\TestLog.txt", loaderException.Message);
                                    System.IO.File.AppendAllText("C:\\TestLog.txt", loaderException.StackTrace);
                                }
                            }

                            return true;

                        }

答案 1 :(得分:0)

当我从MVC 2升级项目并在web.config中遇到一些版本问题时,我隐约回想起与MVC 3有类似问题。

尝试启用融合程序集日志绑定,看看是否可以找到负载失败的原因。

http://www.hanselman.com/blog/BackToBasicsUsingFusionLogViewerToDebugObscureLoaderErrors.aspx

我在一段时间后发现了一个脚本,这使我能够在IIS中更好地使用融合日志(我遇到的问题是它没有在IIS中运行)。