Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/301.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# web应用程序在托管后不工作_C#_Asp.net Mvc 4_Hosting - Fatal编程技术网

C# web应用程序在托管后不工作

C# web应用程序在托管后不工作,c#,asp.net-mvc-4,hosting,C#,Asp.net Mvc 4,Hosting,我在VisualStudio2010中使用C#和ASP.NETMVC4(移动模板应用程序)制作了一个web应用程序。 现在,当我通过VisualStudio运行它时,它工作得很好。但现在我已经在我的网站上托管了它,我不断收到以下错误: “/test”应用程序中出现服务器错误 无法加载一个或多个请求的类型。有关详细信息,请检索LoaderExceptions属性 描述:执行当前web请求期间发生未处理的异常。请查看堆栈跟踪以了解有关错误的更多信息以及错误在代码中的起源 异常详细信息:System.

我在VisualStudio2010中使用C#和ASP.NETMVC4(移动模板应用程序)制作了一个web应用程序。 现在,当我通过VisualStudio运行它时,它工作得很好。但现在我已经在我的网站上托管了它,我不断收到以下错误:

“/test”应用程序中出现服务器错误

无法加载一个或多个请求的类型。有关详细信息,请检索LoaderExceptions属性

描述:执行当前web请求期间发生未处理的异常。请查看堆栈跟踪以了解有关错误的更多信息以及错误在代码中的起源

异常详细信息:System.Reflection.ReflectionTypeLoadException:无法加载一个或多个请求的类型。有关详细信息,请检索LoaderExceptions属性

源错误:

在执行当前web请求期间生成了未经处理的异常。有关异常的起源和位置的信息可以使用下面的异常堆栈跟踪来识别

[ReflectionTypeLoadException: Unable to load one or more of the requested types.      Retrieve the LoaderExceptions property for more information.]
System.Reflection.RuntimeModule.GetTypes(RuntimeModule module) +0
System.Reflection.RuntimeModule.GetTypes() +4
System.Reflection.Assembly.GetTypes() +78
System.Data.Entity.ModelConfiguration.Mappers.TypeMapper.<.ctor>b__1(Assembly a) +11
System.Linq.<SelectManyIterator>d__14`2.MoveNext() +238
System.Collections.Generic.List`1.InsertRange(Int32 index, IEnumerable`1 collection) +395
System.Data.Entity.ModelConfiguration.Mappers.TypeMapper..ctor(MappingContext mappingContext) +253
System.Data.Entity.DbModelBuilder.MapTypes(EdmModel model) +114
System.Data.Entity.DbModelBuilder.Build(DbProviderManifest providerManifest, DbProviderInfo providerInfo) +112
System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection) +59
System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext) +62
System.Data.Entity.Internal.RetryLazy`2.GetValue(TInput input) +117
System.Data.Entity.Internal.LazyInternalContext.InitializeContext() +453
System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) +18
System.Data.Entity.Internal.Linq.InternalSet`1.Initialize() +56
System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext() +15
System.Data.Entity.Internal.Linq.InternalSet`1.ActOnSet(Action action, EntityState newState, Object entity, String methodName) +67
System.Data.Entity.Internal.Linq.InternalSet`1.Add(Object entity) +150
System.Data.Entity.DbSet`1.Add(TEntity entity) +42
PrayerTimes.Models.MosqueRepository.AddError(String error) in MosqueRepository.cs:74
PrayerTimes.Controllers.MosqueController.Index() in MosqueController.cs:57
lambda_method(Closure , ControllerBase , Object[] ) +40
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +17
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +188
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27
System.Web.Mvc.Async.<>c__DisplayClass42.<BeginInvokeSynchronousActionMethod>b__41()+28
System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +12
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +50
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult syncResult) +29
System.Web.Mvc.Async.<>c__DisplayClass39.<BeginInvokeActionMethodWithFilters>b__33() +59
System.Web.Mvc.Async.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49() +240
System.Web.Mvc.Async.<>c__DisplayClass37.<BeginInvokeActionMethodWithFilters>b__36(IAsyncResult asyncResult) +12
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +50
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +31
System.Web.Mvc.Async.<>c__DisplayClass2a.<BeginInvokeAction>b__20() +23
System.Web.Mvc.Async.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult) +128
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +50

我在数据库中创建了一个错误表,并试图将上述代码中的错误添加到该表中,但这也不起作用。有人能帮忙吗?非常感谢

通常,托管时出现MVC错误意味着服务器上未安装MVC,因此无法加载所需的DLL之一

您可以通过将所有DLL复制到应用程序的bin目录来解决此问题

如果您在项目中为MVC内容(System.Web.MVC、System.Web.Routing等)的引用将“Copy Local”标志设置为true,则它会将它们复制到bin目录中供您发布。有一个更简单的方法,但我忘记了捷径

编辑


-可部署依赖关系。但是如果评论是准确的,这个功能是在VS2010中的,但是在VS2012中被删除了,所以你仍然需要做“复制本地”的事情。

当你有一个网站项目,并且你的计算机上的每件事都正常,而托管网站上的某些事情不正确时,我建议你做以下工作:

  • 在主机上检查项目的.net framework版本与web服务器的.net framework版本。他们必须平等

  • 将项目中的所有引用文件复制到托管网站(本地bin----到-->托管bin)

    • 对于这项工作,您可以将项目中每个引用的“复制到本地””属性设置为“TRUE”。例如,对于MVC项目,您可以按照以下指南页面进行操作:

    • 查找参考文件的所有依赖项,并将它们复制到主机上的bin文件夹(您可以使用VS的添加可部署依赖项功能)

  • 检查主机上文件和文件夹的读写权限(临时文件夹、日志文件夹、上载文件夹和…)

  • 再次检查项目,查看是否更改本地地址并将其转换为相对地址(e:\a\b\website\images\1.jpg…=to=>images\1.jpg或http://localhost/images/1.jpg=to=>images/1.jpg)

  • 更改某些基本设置(例如.net版本)时,重新启动主机上的某些服务(例如web服务器或…)

  • 如果您正在使用一些COM引用,请检查它们是否安装在具有相同版本的目标计算机上

编辑:

  • 选中“

您是否已在主机上检查网站的.net framework版本的web服务器设置?它必须与项目的.net framework版本相同。是的,我的项目和主机都使用.net framework 4您是否尝试发布基本MVC4项目?这至少可以告诉您问题是MVC还是您的项目的特定问题(如第三方依赖关系、构建配置等)。可以说,我还没有发布一个基本项目。但是目前不起作用的项目是在早期阶段发布的,以前工作得很好。谢谢,是的,这是我遇到的解决方案之一。我已将所有引用设置为true。使用“可部署依赖项”选项后,我再次托管了我的应用程序。我现在遇到此错误:无法加载文件或程序集“DotNetOpenAuth.Core,Version=4.0.0.0,Culture=neutral,PublicKeyToken=2780ccd10d57b246”或其依赖项之一。系统找不到指定的文件。Booya,找到了。这是一个第三方库,位于您的计算机上的某个位置,所以只需要复制它。如果在项目中未直接引用,则必须间接引用。要在本地将其放入bin,您可以在项目中添加引用,或创建一个
\u bin\u deployableAssemblies
目录并将其添加到该目录中,它将自动复制到bin。在Visual Studio中,您不需要在项目中包含bin目录。您只需要包含输入文件(代码文件、引用等)。bin目录用于输出文件(编译的DLL)。从Visual Studio发布时,它将发布所需的文件(网页、配置文件、DLL)。对于MVC,您发布的目录应该包括视图目录、web.config、global.asax、任何内容(CSS、JS、图像等)和包含所有DLL(此项目的DLL,以及您的每个引用)的bin目录。如果它仍然不起作用,我不得不相信这与您的第三方库DotNetOpenAuth.Core有关(这是您提到的唯一一个库,如果您有更多,它可能是其中的任何一个)。它可能不是MVC、ASP.NET或.NET或任何与框架相关的东西。我认为你唯一的方法是从你的项目中逐渐删除(暂时)东西并一直发布直到它生效,或者从一个全新的开始,逐渐添加东西并发布直到它不起作用。一旦你能证明
try
{
 //The code that causes the error goes here.
}
catch (ReflectionTypeLoadException ex)
{
StringBuilder sb = new StringBuilder();
foreach (Exception exSub in ex.LoaderExceptions)
{
    sb.AppendLine(exSub.Message);
    if (exSub is FileNotFoundException)
    {
        FileNotFoundException exFileNotFound = exSub as FileNotFoundException;
        if(!string.IsNullOrEmpty(exFileNotFound.FusionLog))
        {
            sb.AppendLine("Fusion Log:");
            sb.AppendLine(exFileNotFound.FusionLog);
        }
    }
    sb.AppendLine();
 }
 string errorMessage = sb.ToString();
 //Display or log the error based on your application.
 }
    <system.web>
        <securityPolicy>
              <trustLevel name="Full" policyFile="internal"/>
        </securityPolicy>
    </system.web>
using System.IO;
using System.Reflection;

try
{
    //The code that causes the error goes here.
}
catch (ReflectionTypeLoadException ex)
{
    StringBuilder sb = new StringBuilder();
    foreach (Exception exSub in ex.LoaderExceptions)
    {
        sb.AppendLine(exSub.Message);
        if (exSub is FileNotFoundException)
        {
            FileNotFoundException exFileNotFound = exSub as FileNotFoundException;
            if(!string.IsNullOrEmpty(exFileNotFound.FusionLog))
            {
                sb.AppendLine("Fusion Log:");
                sb.AppendLine(exFileNotFound.FusionLog);
            }
        }
        sb.AppendLine();
    }
    string errorMessage = sb.ToString();
    //Display or log the error based on your application.
}