Note that there are some explanatory texts on larger screens.

plurals
  1. POCustom Route is not called for ASP.NET MVC 3 application .NET 4
    primarykey
    data
    text
    <p>I've tried to create custom route for *.ogg file which is played in website with HTML 5 audio tag.</p> <p>The fact is that FireFox doesn't play ogg if we don't provide application/ogg as ContentType. Unlike Chrome plays ogg without extra work.</p> <p>By the way, I think custom route and register it in Global.asax is a good solution and reusable code. For every path with .ogg extension, server sends ogg file with application/ogg ContentType. </p> <p>The problem is that I don't know why path with *.ogg is not processed with custom route.</p> <p>This is my code for OggHandler.cs</p> <pre><code> public class OggHandler : IRouteHandler, IHttpHandler { public IHttpHandler GetHttpHandler(RequestContext requestContext) { return this; } /// &lt;summary&gt; /// process ogg file /// &lt;/summary&gt; /// &lt;param name="context"&gt;&lt;/param&gt; public void ProcessRequest(HttpContext context) { var request = context.Request; var response = context.Response; try { //response ogg file with Content Type Header response.ContentType = "application/ogg"; response.WriteFile(request.PhysicalPath); } catch (Exception ex) { response.Write("&lt;html&gt;\r\n"); response.Write("&lt;head&gt;&lt;title&gt;Ogg HTTP Handler&lt;/title&gt;&lt;/head&gt;\r\n"); response.Write("&lt;body&gt;\r\n"); response.Write("&lt;h1&gt;" + ex.Message + "&lt;/h1&gt;\r\n"); response.Write("&lt;/body&gt;\r\n"); response.Write("&lt;/html&gt;"); } } public bool IsReusable { get { return true; } } } </code></pre> <p>and the registration in Global.asax</p> <pre><code> public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.Add(new Route ( "{resource}.ogg/{*pathInfo}" , new OggHandler() )); routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults ); } </code></pre> <p>Hope to get good suggestion from you all. :)</p> <p>Lately, I also attached simple project file as the following link.</p> <p><a href="http://codesanook.com/shared/MvcOgg.zip" rel="nofollow">http://codesanook.com/shared/MvcOgg.zip</a></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.
 

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