/Visual Studio 2008/CSASPNETMVCCustomActionFilter/Controllers/HomeController.cs

# · C# · 50 lines · 23 code · 4 blank · 23 comment · 0 complexity · 1c9c8e4816d61fd583885ec1e770609e MD5 · raw file

  1. /****************************** Module Header ******************************\
  2. * Module Name: MessageModifierActionFilter.cs
  3. * Project: CSASPNETMVCCustomActionFilter
  4. * Copyright (c) Microsoft Corporation.
  5. *
  6. * The CSASPNETMVCCustomActionFilter sample demonstrates how to use C# codes to
  7. * create custom ActionFilters for ASP.NET MVC web application. In this sample,
  8. * there are two custom ActionFilters, one is used for customizing ViewData
  9. * before page view result get executed and rendered; another is used for
  10. * perform logging within the various events during the processing of custom
  11. * ActionFilters.
  12. *
  13. *
  14. * This source is subject to the Microsoft Public License.
  15. * See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
  16. * All other rights reserved.
  17. *
  18. * History:
  19. * * 10/10/2009 1:35 PM Steven Cheng Created
  20. ***************************************************************************/
  21. using System;
  22. using System.Collections.Generic;
  23. using System.Linq;
  24. using System.Web;
  25. using System.Web.Mvc;
  26. namespace CSASPNETMVCCustomActionFilter.Controllers
  27. {
  28. [HandleError]
  29. public class HomeController : Controller
  30. {
  31. // Use declarative attribute to registetr the MessageModifier ActionFilter
  32. [CSASPNETMVCCustomActionFilter.ActionFilters.MessageModifierActionFilter]
  33. public ActionResult Index()
  34. {
  35. // The original value of Message data returned via ViewData collection
  36. ViewData["Message"] = "Welcome to ASP.NET MVC!";
  37. return View();
  38. }
  39. // Use declarative attribute to registetr the Logging ActionFilter
  40. [CSASPNETMVCCustomActionFilter.ActionFilters.TextLogActionFilter(LogFileName = @"D:\temp\logs\mvc_action_filter.log")]
  41. public ActionResult About()
  42. {
  43. return View();
  44. }
  45. }
  46. }