0

How can I do the following?

I want a user to browse to https://localhost/Registration/GetCaptchaAudioInternetExplorer.wav and have it run the action of GetCaptchaAudioInternetExplorer on the Registration controller, which serves an audio/wav file.

What works for me right now is browsing to https://localhost/Registration/GetCaptchaAudioInternetExplorer

But what do I need to do to make https://localhost/Registration/GetCaptchaAudioInternetExplorer.wav route to the same action? Is there a way in MVC to specify action routes for something like this?

Alexandru
  • 12,264
  • 17
  • 113
  • 208
  • http://stackoverflow.com/questions/11728846/dots-in-url-causes-404-with-asp-net-mvc-and-iis – Shyju Jan 19 '16 at 20:29

2 Answers2

1

You can use URL Rewrite for IIS (7+) to do this, basically:

<rule name="Rewrite Wav Files" stopProcessing="true">
  <match url="^Registration/?(.*)\.wav$" />
  <action type="Rewrite" url="/Registration/{R:1}" />
</rule>

That will strip off the extension and send it to the controller. It's rewritten so it should still present as Registration/GetCaptchaAudioInternetExplorer.wav in the browser.


Potentially you can try setting relaxedUrlToFileSystemMapping:

<system.web>
<httpRuntime relaxedUrlToFileSystemMapping="true" />

But with .wav being a real thing, I'm not sure if that will work. More detail on Haacked.


A final alternative you can enable RAMMFAR:

RAMMFAR means "runAllManagedModulesForAllRequests" and refers to this optional setting in your web.config.

 <system.webServer>   
     <modules runAllManagedModulesForAllRequests="true" />    
 </system.webServer>

That should send all requests through MVC regardless of extension. I say final, as this has a performance hit.

Matthew Verstraete
  • 6,335
  • 22
  • 67
  • 123
NikolaiDante
  • 18,469
  • 14
  • 77
  • 117
  • 1
    I can't use IIS rules because they are not guaranteed to be there :( I thought there would be a way of doing this with MVC routes, no??? http://www.asp.net/mvc/overview/older-versions-1/controllers-and-routing/asp-net-mvc-routing-overview-cs – Alexandru Jan 19 '16 at 20:31
  • Thanks for the ideas...I found a bit of a workaround myself while researching; please check out my answer when I post it. – Alexandru Jan 19 '16 at 20:51
0

A little bit of a spinoff, but I was able to instead get https://localhost/Registration/GetCaptchaAudioInternetExplorer/clip.wav routing to my GetCaptchaAudioInternetExplorer action.

Two simple changes:

1) Add this route to your action:

[Route("clip.wav")]
public async Task<ActionResult> GetCaptchaAudioInternetExplorer()

2) Add this handler into your web.config:

<system.webServer><handlers><add name="Wave File Handler" path="clip.wav" verb="GET" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
Alexandru
  • 12,264
  • 17
  • 113
  • 208