Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to filter Logging in ASP MVC?
    primarykey
    data
    text
    <p>I am developing an ASP .Net MVC 3 application using C# and SQL Server 2005. I want to customize my interface depending on the type of user logged. I was following <a href="http://msdn.microsoft.com/en-us/vs2010trainingcourse_aspnetmvc3customactionfilters_topic2" rel="nofollow">this tuto</a> in the microsoft site and i am stuck when he use ActionLog instance in the filter class (ActionLogFilterAttribute). Infact, this class is declared in 'StoreDB.designer.cs' class which i don't have because i created my project using the 'code first' method of Entity Framework. I have only this class for the context :</p> <pre><code>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&lt;GammeContext&gt;()); } public DbSet&lt;Account&gt; Accounts { get; set; } public DbSet&lt;Ns_AFaire&gt; Ns_AFaires { get; set; } public DbSet&lt;Famille&gt; Familles { get; set; } public DbSet&lt;Fonction&gt; Fonctions { get; set; } public DbSet&lt;Fonction_Poste&gt; Fonction_Postes { get; set; } public DbSet&lt;Gamme&gt; Gammes { get; set; } public DbSet&lt;Historique&gt; Historiques { get; set; } public DbSet&lt;Ligne&gt; Lignes { get; set; } public DbSet&lt;Phase&gt; Phases { get; set; } public DbSet&lt;Poste&gt; Postes { get; set; } public DbSet&lt;Produit&gt; Produits { get; set; } public DbSet&lt;Profile_Ga&gt; Profil_Gas { get; set; } public DbSet&lt;Sous_Famille&gt; Sous_Familles { get; set; } public DbSet&lt;UF&gt; UFs { get; set; } public DbSet&lt;User&gt; Users { get; set; } public DbSet&lt;Num_Serie&gt; Num_Series { get; set; } protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Conventions.Remove&lt;System.Data.Entity.ModelConfiguration.Conventions.PluralizingTableNameConvention&gt;(); } } } </code></pre> <p>and this is the filter class that i created :</p> <pre><code>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); } } } </code></pre> <p>So, is there any solution ??</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload