c# - How to filter Logging in ASP MVC? -
i developing asp .net mvc 3 application using c# , sql server 2005. want customize interface depending on type of user logged. following this tuto in microsoft site , stuck when use actionlog instance in filter class (actionlogfilterattribute). infact, class declared in 'storedb.designer.cs' class don't have because created project using 'code first' method of entity framework. have class context :
using system; using system.collections.generic; using system.linq; using system.web; using system.data.entity; using system.componentmodel.dataannotations; namespace mvcapplication2.models { public class gammecontext : dbcontext { public gammecontext() { database.setinitializer(new dropcreatedatabaseifmodelchanges<gammecontext>()); } public dbset<account> accounts { get; set; } public dbset<ns_afaire> ns_afaires { get; set; } public dbset<famille> familles { get; set; } public dbset<fonction> fonctions { get; set; } public dbset<fonction_poste> fonction_postes { get; set; } public dbset<gamme> gammes { get; set; } public dbset<historique> historiques { get; set; } public dbset<ligne> lignes { get; set; } public dbset<phase> phases { get; set; } public dbset<poste> postes { get; set; } public dbset<produit> produits { get; set; } public dbset<profile_ga> profil_gas { get; set; } public dbset<sous_famille> sous_familles { get; set; } public dbset<uf> ufs { get; set; } public dbset<user> users { get; set; } public dbset<num_serie> num_series { get; set; } protected override void onmodelcreating(dbmodelbuilder modelbuilder) { modelbuilder.conventions.remove<system.data.entity.modelconfiguration.conventions.pluralizingtablenameconvention>(); } } } and filter class created :
using system; using system.collections.generic; using system.linq; using system.web; using system.web.mvc; using mvcapplication2.models; namespace mvcapplication2.filters { public class actionlogfilterattribute : actionfilterattribute, iactionfilter { public override void onactionexecuting(actionexecutingcontext filtercontext) { gammecontext db = new gammecontext(); actionlog log = new actionlog() { controller = filtercontext.actiondescriptor.controllerdescriptor.controllername, action = filtercontext.actiondescriptor.actionname, ip = filtercontext.httpcontext.request.userhostaddress, datetime = filtercontext.httpcontext.timestamp }; db.addtoactionlogs(log); db.savechanges(); base.onactionexecuting(filtercontext); } } } so, there solution ??
the actionlog instance using enitity related actionlog table.
what need add own actionlog entity - :)
Comments
Post a Comment