我的Global.asax包含下面的代码,异常“项目已被添加。”在MetaModel.Register
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),新ContextConfiguration(){ScaffoldAllTables = true});
完整的堆栈跟踪:
[ArgumentException的:项目已添加。键入字典:'APP.SQLAppModel.sEntities'键被添加:'APP.SQLAppModel.sEntities'] System.Collections.Hashtable.Insert(Object key,Object nvalue,Boolean add)+9352427 System.Collections.Hashtable。添加(对象键,对象值)+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(Type contextType,ContextConfiguration配置)+88 SAMI.Global.RegisterRoutes(RouteCollection routes)in C :\ Anand \ SAMI \ SAMI \ SAMI \ Global.asax.cs:42 C:\ Anand \ SAMI \ SAMI \ SAMI \ Global.asax.cs中的SAMI.Global.Session_Start(对象发件人,EventArgs e):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一步,布尔& completedSynchronously)184
请让我知道如何解决这个问题。我很难确定问题。
为什么我在Session_Start中调用RegisterRoutes的原因是,您可能已经注意到,有两个MetaModel,并不是所有的用户都应该看到这两个模型。根据已登录用户的角色(从数据库中获得),我只想显示来自适用元模型的表格。这种基于角色访问的逻辑写在RegisterRoutes方法内部。我不知道这是否是管理基于角色的访问的正确方式。任何建议,这是非常感谢。提前致谢。 – Anand