我的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开发Web服务器调试我的应用程序时,应用程序运行正常并提供所需的结果。
但是当我停止调试并再次启动它时,它给出了以下异常,
项目已添加。键入字典:添加'APP.SQLAppModel.sEntities'键:'APP.SQLAppModel.sEntities'
抛出此异常的行是_a_Model.RegisterContext(typeof(SQLAppModel.aEntities),new ContextConfiguration(){ScaffoldAllTables = true});
完成堆栈跟踪:
[ArgumentException:Item已被添加。键入字典:添加'APP.SQLAppModel.sEntities'键:'APP.SQLAppModel.sEntities'] System.Collections.Hashtable.Insert(Object key,Object nvalue,Boolean add)+9352427 System.Collections.Hashtable.Add(Object key,Object value)+11 System.Web.DynamicData.MetaModelManager.AddModel(类型contextType,MetaModel模型)+96 System.Web.DynamicData.MetaModel.RegisterContext(DataModelProvider dataModelProvider,ContextConfiguration configuration)+727 System.Web.DynamicData.MetaModel.RegisterContext(Func`1 contextFactory,ContextConfiguration配置)+390 System.Web.DynamicData.MetaModel.RegisterContext(类型contextType,ContextConfiguration配置)+88 在C:\ Anand \ SAMI \ SAMI \ SAMI \ Global.asax.cs中的SAMI.Global.RegisterRoutes(RouteCollection路由):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(Object source,EventArgs e,AsyncCallback cb,Object extraData)+561 System.Web.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()+96 System.Web.HttpApplication.ExecuteStep(IExecutionStep step,Boolean&amp; completedSynchronously)+184
请让我知道如何解决这个问题。我很难确定问题。
答案 0 :(得分:0)
问题是你从Session_Start调用RegisterRoutes,因此可以多次调用它。您需要从Application_Start调用它。