簡體   English   中英

Windows 2012上的MVC5部署到IIS(Visual Studio 2013)

[英]MVC5 Deploy to IIS on Windows 2012 (Visual Studio 2013)

我一直在使用EF6在VS2013中開發MVC5應用程序。 我在開發環境中沒有任何問題,但是當發布到Win 2012 IIS服務器並運行應用程序時,我遇到了許多頁面錯誤。

我面臨的錯誤似乎在頁面中是一致的。

“屬性'CountFrequency'不是String或Byte數組。只能為String和Byte數組屬性配置Length。”

第35行:第36行:第37行:@foreach(模型中的var項)第38行:{第39行:

這是堆棧跟蹤:

*

[InvalidOperationException: The property 'CountFrequency' is not a String or Byte array. Length can only be configured for String and Byte array properties.]
   System.Data.Entity.ModelConfiguration.Configuration.ConventionPrimitivePropertyConfiguration.HasMaxLength(Int32 maxLength) +612
   System.Data.Entity.ModelConfiguration.Conventions.PrimitivePropertyAttributeConfigurationConvention`1.<.ctor>b__1(ConventionPrimitivePropertyConfiguration configuration, IEnumerable`1 attributes) +114
   System.Data.Entity.ModelConfiguration.Configuration.PropertyConfigurationConventionDispatcher.Dispatch() +38
   System.Data.Entity.ModelConfiguration.Configuration.ConventionsConfiguration.ApplyPropertyConfiguration(PropertyInfo propertyInfo, Func`1 propertyConfiguration, ModelConfiguration modelConfiguration) +176
   System.Data.Entity.ModelConfiguration.Configuration.ConventionsConfiguration.ApplyPropertyConfiguration(PropertyInfo propertyInfo, Func`1 propertyConfiguration, ModelConfiguration modelConfiguration) +218
   System.Data.Entity.ModelConfiguration.Mappers.PropertyMapper.MapPrimitiveOrComplexOrEnumProperty(PropertyInfo propertyInfo, Func`1 structuralTypeConfiguration, Boolean discoverComplexTypes) +650
   System.Data.Entity.ModelConfiguration.Mappers.<>c__DisplayClass14.<MapEntityType>b__e(PropertyMapper m, PropertyInfo p) +46
   System.Data.Entity.ModelConfiguration.Mappers.TypeMapper.MapStructuralElements(Type type, ICollection`1 annotations, Action`2 propertyMappingAction, Boolean mapDeclaredPropertiesOnly, Func`1 structuralTypeConfiguration) +516
   System.Data.Entity.ModelConfiguration.Mappers.TypeMapper.MapEntityType(Type type) +876
   System.Data.Entity.<>c__DisplayClassd.<MapTypes>b__7(Type type) +16
   System.Linq.WhereListIterator`1.MoveNext() +165
   System.Data.Entity.Utilities.IEnumerableExtensions.Each(IEnumerable`1 ts, Action`1 action) +168
   System.Data.Entity.DbModelBuilder.MapTypes(EdmModel model) +428
   System.Data.Entity.DbModelBuilder.Build(DbProviderManifest providerManifest, DbProviderInfo providerInfo) +281
   System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection) +288
   System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext) +94
   System.Data.Entity.Internal.RetryLazy`2.GetValue(TInput input) +248
   System.Data.Entity.Internal.LazyInternalContext.InitializeContext() +618
   System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) +26
   System.Data.Entity.Internal.Linq.InternalSet`1.Initialize() +72
   System.Data.Entity.Internal.Linq.InternalSet`1.GetEnumerator() +21
   ASP._Page_Views_Logic_List_cshtml.Execute() in c:\inetpub\Internal\KSCycleCounts\Views\Logic\List.cshtml:37
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +280
   System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +125
   System.Web.WebPages.StartPage.ExecutePageHierarchy() +143
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +110
   System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +380
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +109
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +890
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +97
   System.Web.Mvc.Async.<>c__DisplayClass1e.<BeginInvokeAction>b__1b(IAsyncResult asyncResult) +241
   System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +29
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +111
   System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +53
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +19
   System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__4(IAsyncResult asyncResult, ProcessRequestState innerState) +51
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +111
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +606
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +288

*

我知道我的連接字符串是有效的並且正在工作。 在Windows 2012中,我安裝了所有角色(ASP.NET 4.5和.NET 4.5)。 在IIS中,我已將我的應用程序池配置為使用.NET 4,並使用管理員帳戶作為測試標識。

謝謝!

雖然這個問題在我回答的時候已經快一年了,但是我最近在嘗試循環實體框架DbSet時遇到了同樣的異常。

我最初有一個字符串作為字段:

public class Table
{
  [StringLength(20)]
  public string Ref {get;set;}
}

我后來改為int:

public class Table
{
  [StringLength(20)]  // <-- hint: int doesn't need a string-length limitation
  public int Ref {get;set;}
}

請注意,我保留了StringLength屬性......但它自然與int無關,最終拋出了異常。 傻我。 希望它從我失去的時間中拯救別人,永遠不會重獲:)

我也有同樣的問題。 您正在訪問的表並不總是導致錯誤的表。 對我來說,我正在做一個名為bnapp_tr的表

List<bnapp_tr> bn = db.bnapp_tr.ToList();

但錯誤發生在我后來創建的一個類中,其中有一個被錯誤注釋的字段

[StringLength(25)] // <---Here
public decimal? frec_no { get; set; }

StringLength注釋不可用於decimal? 它沒有任何意義。 但是我在編碼時不小心這樣做了。 所以我剛剛刪除了注釋。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM