SanSYS

Untitled

Mar 10th, 2015
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.63 KB | None | 0 0
  1. public interface IHttpHandlerBase : IHttpHandler
  2. {
  3.     void RequestContext { get; set; }
  4. }
  5.  
  6. public class GenericRouteHandler<T> : IRouteHandler
  7.     where T : IHttpHandlerBase, new()
  8. {
  9.     public IHttpHandler GetHttpHandler(RequestContext requestContext)
  10.     {
  11.         var retVal = new T();
  12.         retVal.RequestContext = requestContext;
  13.         return retVal;
  14.     }
  15. }
  16.  
  17. public class ImageHandler : IHttpHandlerBase
  18. {
  19.    ...
  20. }
  21.  
  22. // Это прописать в инициализации правил маршрутизации
  23. RouteTable.Routes.Add(new Route("Image/{ImageID}", new GenericRouteHandler<ImageHandler>()));
Advertisement
Add Comment
Please, Sign In to add comment