【问题标题】:Server Error in '/' Application when publish to Azure发布到 Azure 时“/”应用程序中的服务器错误
【发布时间】:2015-04-20 08:47:33
【问题描述】:

我从以前的 NopCommerce 网站复制了源代码,复制并重命名了 Azure 上的数据库,并更新了 settings.txt 文件以指向新数据库。唯一的其他更改是对 css 的更改。

当我在 localhost 上运行新站点时,它可以完美运行,但是,当我从 VS 发布到 Azure 然后浏览到 URL 时,我收到一个错误 - “/”应用程序中的服务器错误。对于我的一生,我无法弄清楚这一点,并想知道是否有其他人经历过这种情况。

我正在使用 Nop 3.5

我的直觉告诉我,我的连接字符串有问题,但是,为什么在 localhost 上可以工作,但在发布时却不行?...

下面是异常详情和堆栈跟踪

提前感谢您的帮助

“/”应用程序中的服务器错误。 参数“nameOrConnectionString”不能为空、空或仅包含空格。 说明:执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。

异常详细信息:System.ArgumentException:参数“nameOrConnectionString”不能为空、空或仅包含空格。

来源错误:

生成此未处理异常的源代码只能在调试模式下编译时显示。要启用此功能,请按照以下步骤之一,然后请求 URL:

  1. 在产生错误的文件顶部添加“Debug=true”指令。示例:

或:

2) 将以下部分添加到应用程序的配置文件中:

<configuration>
   <system.web>
       <compilation debug="true"/>
   </system.web>
</configuration>

请注意,第二种技术将导致给定应用程序中的所有文件都以调试模式编译。第一种技术将导致仅在调试模式下编译该特定文件。

重要提示:在调试模式下运行应用程序确实会产生内存/性能开销。在部署到生产场景之前,您应该确保应用程序已禁用调试。

堆栈跟踪:

[ArgumentException: The argument 'nameOrConnectionString' cannot be null, empty or contain only white space.]
   System.Data.Entity.Utilities.Check.NotEmpty(String value, String parameterName) +61
   System.Data.Entity.DbContext..ctor(String nameOrConnectionString) +22
   Nop.Web.Framework.<>c__DisplayClass15.<Register>b__9(IComponentContext c) +42
   Autofac.<>c__DisplayClass10`1.<Register>b__f(IComponentContext c, IEnumerable`1 p) +10
   Autofac.Builder.<>c__DisplayClass1`1.<ForDelegate>b__0(IComponentContext c, IEnumerable`1 p) +14
   Autofac.Core.Activators.Delegate.DelegateActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters) +32
   Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters) +48
   Autofac.Core.Resolving.InstanceLookup.<Execute>b__0() +8
   Autofac.Core.Lifetime.LifetimeScope.GetOrCreateAndShare(Guid id, Func`1 creator) +120
   Autofac.Core.Resolving.InstanceLookup.Execute() +132
   Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable`1 parameters) +133
   Autofac.Core.Resolving.InstanceLookup.ResolveComponent(IComponentRegistration registration, IEnumerable`1 parameters) +24
   Autofac.Core.Activators.Reflection.<>c__DisplayClass2.<CanSupplyValue>b__0() +31
   Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate() +94
   Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters) +185
   Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters) +48
   Autofac.Core.Resolving.InstanceLookup.<Execute>b__0() +8
   Autofac.Core.Lifetime.LifetimeScope.GetOrCreateAndShare(Guid id, Func`1 creator) +120
   Autofac.Core.Resolving.InstanceLookup.Execute() +132
   Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable`1 parameters) +133
   Autofac.Core.Resolving.InstanceLookup.ResolveComponent(IComponentRegistration registration, IEnumerable`1 parameters) +24
   Autofac.Core.Activators.Reflection.<>c__DisplayClass2.<CanSupplyValue>b__0() +31
   Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate() +94
   Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters) +185
   Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters) +48
   Autofac.Core.Resolving.InstanceLookup.<Execute>b__0() +8
   Autofac.Core.Lifetime.LifetimeScope.GetOrCreateAndShare(Guid id, Func`1 creator) +120
   Autofac.Core.Resolving.InstanceLookup.Execute() +132
   Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable`1 parameters) +133
   Autofac.Core.Resolving.InstanceLookup.ResolveComponent(IComponentRegistration registration, IEnumerable`1 parameters) +24
   Autofac.Core.Activators.Reflection.<>c__DisplayClass2.<CanSupplyValue>b__0() +31
   Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate() +94
   Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters) +185
   Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters) +48
   Autofac.Core.Resolving.InstanceLookup.<Execute>b__0() +8
   Autofac.Core.Lifetime.LifetimeScope.GetOrCreateAndShare(Guid id, Func`1 creator) +120
   Autofac.Core.Resolving.InstanceLookup.Execute() +132
   Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable`1 parameters) +133
   Autofac.Core.Resolving.InstanceLookup.ResolveComponent(IComponentRegistration registration, IEnumerable`1 parameters) +24
   Autofac.ResolutionExtensions.TryResolveService(IComponentContext context, Service service, IEnumerable`1 parameters, Object& instance) +74
   Autofac.ResolutionExtensions.ResolveService(IComponentContext context, Service service, IEnumerable`1 parameters) +54
   Autofac.ResolutionExtensions.Resolve(IComponentContext context, IEnumerable`1 parameters) +118
   Nop.Web.Framework.SettingsSource.<BuildRegistration>b__5(IComponentContext c, IEnumerable`1 p) +35
   Autofac.Builder.<>c__DisplayClass1`1.<ForDelegate>b__0(IComponentContext c, IEnumerable`1 p) +14
   Autofac.Core.Activators.Delegate.DelegateActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters) +32
   Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters) +48
   Autofac.Core.Resolving.InstanceLookup.<Execute>b__0() +8
   Autofac.Core.Lifetime.LifetimeScope.GetOrCreateAndShare(Guid id, Func`1 creator) +120
   Autofac.Core.Resolving.InstanceLookup.Execute() +132
   Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable`1 parameters) +133
   Autofac.Core.Resolving.ResolveOperation.Execute(IComponentRegistration registration, IEnumerable`1 parameters) +44

[DependencyResolutionException: An exception was thrown while executing a resolve operation. See the InnerException for details. ---> The argument 'nameOrConnectionString' cannot be null, empty or contain only white space. (See inner exception for details.)]
   Autofac.Core.Resolving.ResolveOperation.Execute(IComponentRegistration registration, IEnumerable`1 parameters) +112
   Autofac.Core.Lifetime.LifetimeScope.ResolveComponent(IComponentRegistration registration, IEnumerable`1 parameters) +108
   Autofac.ResolutionExtensions.TryResolveService(IComponentContext context, Service service, IEnumerable`1 parameters, Object& instance) +74
   Autofac.ResolutionExtensions.ResolveService(IComponentContext context, Service service, IEnumerable`1 parameters) +54
   Autofac.ResolutionExtensions.Resolve(IComponentContext context, IEnumerable`1 parameters) +118
   Autofac.ResolutionExtensions.Resolve(IComponentContext context) +46
   Nop.Core.Infrastructure.DependencyManagement.ContainerManager.Resolve(String key, ILifetimeScope scope) +89
   Nop.Core.Infrastructure.NopEngine.Resolve() +55
   FoxNetSoft.Plugin.Misc.RFQ2.UpdateStartUpTask.Execute() +34
   Nop.Core.Infrastructure.NopEngine.RunStartupTasks() +477
   Nop.Core.Infrastructure.NopEngine.Initialize(NopConfig config) +36
   Nop.Core.Infrastructure.EngineContext.Initialize(Boolean forceRecreate) +92
   Nop.Web.MvcApplication.Application_Start() +30

[HttpException (0x80004005): An exception was thrown while executing a resolve operation. See the InnerException for details. ---> The argument 'nameOrConnectionString' cannot be null, empty or contain only white space. (See inner exception for details.)]
   System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +9916673
   System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +118
   System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +172
   System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +336
   System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +296

[HttpException (0x80004005): An exception was thrown while executing a resolve operation. See the InnerException for details. ---> The argument 'nameOrConnectionString' cannot be null, empty or contain only white space. (See inner exception for details.)]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9930568
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254

版本信息:Microsoft .NET Framework 版本:4.0.30319; ASP.NET 版本:4.0.30319.36215

更新

从我评论中的链接我想我需要在下面定义连接字符串??来自 NopObjectContext.cs

namespace Nop.Data
{
    /// <summary>
    /// Object context
    /// </summary>
    public class NopObjectContext : DbContext, IDbContext
    {
        #region Ctor

        public NopObjectContext(string nameOrConnectionString)
            : base(nameOrConnectionString)
        {
            //((IObjectContextAdapter) this).ObjectContext.ContextOptions.LazyLoadingEnabled = true;
        }
     }
}

【问题讨论】:

  • 我从 EF 中的 DbContext 构造函数中识别出 nameOrConnectionString 参数。你在这里传递什么值?你从哪里获得价值?在我看来,您缺少配置点。您的 Autofac IOC 容器是否将其传入?
  • 感谢您的回复。我会调查您提出的这些问题,并会尽快回复您。谢谢
  • @heymega 这对我来说是全新的,所以请和我一起裸露!有一个带有连接字符串的 settings.txt 文件,当在本地执行时,它可以很好地连接到 Azure 上的数据库。我已经阅读了linklink,所以我认为我需要在 DbContext 中定义连接字符串或在 DbContext 中定义无参数构造函数。我将用代码更新我的问题。我正朝着正确的方向前进?谢谢

标签: asp.net-mvc azure nopcommerce


【解决方案1】:

在 NopCommerce 中,连接字符串设置在一个名为 Settings.txt 的文件中,该文件位于您的 Presnetation\Nop.Web\App_Data 文件夹中。但是,它不是解决方案的一部分,因此不会被部署。您可以:

  1. 手动发布该文件。
  2. 将该文件添加到您的Nop.Web 项目并进行部署。

【讨论】:

  • 感谢您的回复。我注意到 settings.txt 没有发布并通过 FTP 将其放入目录中。不幸的是,它引发了另一个错误 - 此网页不可用 DNS_PROBE_FINISHED_NXDOMAIN 找不到服务器,因为 DNS 查找失败。 DNS 是将网站名称转换为其 Internet 地址的网络服务。此错误最常见的原因是没有连接到 Internet 或网络配置错误。也可能是由于 DNS 服务器无响应或防火墙阻止 Google Chrome 访问网络。
  • 这是一个 Chrome 错误,表示您没有互联网连接
  • 这几乎 100% 不相关。只需谷歌DNS_PROBE_FINISHED_NXDOMAIN,您就会发现它与 Chrome 无法找到您所要求的域有关。
  • 显然是的......但是如果 settings.txt 存在,它会抛出 DNS_PROBE_FINISHED_NXDOMAIN,如果不存在,则会抛出“/”应用程序中的服务器错误......
【解决方案2】:

好的,这就是我找到的。

如果 100% 正确,则如果 settings.txt 存在于 App_Data 中,则表明 DNS_PROBE_FINISHED_NXDOMAIN 错误。问题是 Azure 提供的 URL http://yourwebsite.azurewebsites.net/ 不起作用,并且直到自定义域被连接并用于导航到该站点按预期运行的网站。

【讨论】:

    猜你喜欢
    • 2016-02-03
    • 1970-01-01
    • 1970-01-01
    • 2023-03-16
    • 1970-01-01
    • 1970-01-01
    • 2021-11-08
    • 2016-11-08
    • 2016-04-10
    相关资源
    最近更新 更多