My Global.asax содержит следующий код,
public class Global : System.Web.HttpApplication
{
private MetaModel _s_Model = new AdvancedMetaModel();
public MetaModel s_Model
{
get
{
return _s_Model;
}
}
private MetaModel _a_Model = new AdvancedMetaModel();
public MetaModel a_Model
{
get
{
return _a_Model;
}
}
public void RegisterRoutes(RouteCollection routes)
{
Dictionary<Helper.ModelName, MetaModel> registeredRoutes = new Dictionary<Helper.ModelName, MetaModel>();
if (SQLAppModel.ModelQuery.GetUserType() == Utility.Helper.UserType.ApplicationAdmin
|| SQLAppModel.ModelQuery.GetUserType() == Utility.Helper.UserType.SystemAdmin)
{
_a_Model.RegisterContext(typeof(SQLAppModel.aEntities), new ContextConfiguration() { ScaffoldAllTables = true });
/** Full Permission **/
routes.Add(new DynamicDataRoute("{table}/ListDetails.aspx")
{
Action = PageAction.List,
ViewName = "ListDetails",
Model = a_Model
});
routes.Add(new DynamicDataRoute("{table}/ListDetails.aspx")
{
Action = PageAction.Details,
ViewName = "ListDetails",
Model = a_Model
});
registeredRoutes.Add(Helper.ModelName.Administration, a_Model);
}
string supportedEnvironments = System.Configuration.ConfigurationManager.AppSettings[Helper.SupportedEnvironmentsAppSettingsKey].ToString();
foreach (string supportedEnvironment in supportedEnvironments.Split(','))
{
foreach (var supportedSystem in SQLAppModel.ModelQuery.GetSupportedSystems(supportedEnvironment, true))
{
if (supportedEnvironment.ToUpper() == "ORACLE")
{
if (supportedSystem.Name.ToUpper() == "ADS")
{
_s_model.RegisterContext(typeof(OracleAppModel.sEntities), new ContextConfiguration()
{
ScaffoldAllTables = true
});
routes.Add(new DynamicDataRoute("{table}/ReadOnlyListDetails.aspx")
{
Action = PageAction.List,
ViewName = "ReadOnlyListDetails",
Model = s_model
});
routes.Add(new DynamicDataRoute("{table}/ReadOnlyListDetails.aspx")
{
Action = PageAction.Details,
ViewName = "ReadOnlyListDetails",
Model = s_model
});
registeredRoutes.Add(Helper.ModelName.ADS, s_model);
}
}
}
HttpContext.Current.Session[Helper.RegisteredRouteListSessionKey] = registeredRoutes;
}
void Application_Start(object sender, EventArgs e)
{
}
void Session_Start(object sender, EventArgs e)
{
SQLAppModel.ModelQuery.GetApplicationUser();
RegisterRoutes(RouteTable.Routes);
}
}
Когда я впервые отлаживаю свое приложение на веб-сервере разработки ASP.NET, приложение работает нормально и дает желаемый результат.
Но когда я остановил отладку и запустил ее снова, выдается следующее исключение:
Товар уже добавлен. Ключ в словаре: 'APP.SQLAppModel.sEntities' Добавляемый ключ: 'APP.SQLAppModel.sEntities'
Строка, которая выбрасывает это исключение: _a_Model.RegisterContext (typeof (SQLAppModel.aEntities), new ContextConfiguration () {ScaffoldAllTables = true});
Полная трассировка стека:
[ArgumentException: элемент уже добавлен. Ключ в словаре: 'APP.SQLAppModel.sEntities' Добавляемый ключ: 'APP.SQLAppModel.sEntities']
System.Collections.Hashtable.Insert (ключ объекта, значение объекта, логическое добавление) +9352427
System.Collections.Hashtable.Add (ключ объекта, значение объекта) +11
System.Web.DynamicData.MetaModelManager.AddModel (Тип contextType, модель MetaModel) +96
System.Web.DynamicData.MetaModel.RegisterContext (DataModelProvider dataModelProvider, конфигурация ContextConfiguration) +727
System.Web.DynamicData.MetaModel.RegisterContext (Func`1 contextFactory, конфигурация ContextConfiguration) +390
System.Web.DynamicData.MetaModel.RegisterContext (Тип contextType, Конфигурация ContextConfiguration) +88
SAMI.Global.RegisterRoutes (маршруты RouteCollection) в C: \ Anand \ SAMI \ SAMI \ SAMI \ Global.asax.cs: 42
SAMI.Global.Session_Start (Отправитель объекта, EventArgs e) в C: \ Anand \ SAMI \ SAMI \ SAMI \ Global.asax.cs: 137
System.Web.SessionState.SessionStateModule.RaiseOnStart (EventArgs e) +8955827
System.Web.SessionState.SessionStateModule.CompleteAcquireState () +148
System.Web.SessionState.SessionStateModule.BeginAcquireState (Источник объекта, EventArgs e, AsyncCallback cb, Объект extraData) +561
System.Web.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute () +96
System.Web.HttpApplication.ExecuteStep (шаг IExecutionStep, логическое и завершено синхронно) + 184
Пожалуйста, дайте мне знать, как это исправить. Мне трудно определить проблему.