0

I currently have a website that is serving static files from a simple website that just points to a directory and I want to replace it by grabbing the files from DropBox.

I already have the files on DropBox and grabbing them is easy BUT I now need a website that will parse the URL to the files and give me the parameters I need to access the files on DropBox.

Typical file URL:

http://companyfiles.mywebsite.com/18/RepZio/companyfiles/subfolder1/SampleFile.docx

The route I configured that I hoped would work:

routes.MapRoute(
                name: "Default",
                url: "{id}/{dropboxfolder}/companyfiles/{path}",
                defaults: new { controller = "CompanyFiles", action = "Index" }
            );

I know my issue is all of the extra /'s in my URL, how can I parse whatever comes after /companyfiles/ to be a single parameter?

I cannot change the URL's that are being called since they already exist everywhere else in my system.

Slee
  • 27,498
  • 52
  • 145
  • 243
  • try using a catchall phrase `url: "{id}/{dropboxfolder}/companyfiles/{*path}",` – shakib Dec 05 '13 at 06:19
  • That actually works until I have a file extension like the .docx, so it seems I need to somehow ignore know file types to get my route to get picked up. – Slee Dec 05 '13 at 12:00
  • does the file `http://companyfiles.mywebsite.com/18/RepZio/companyfiles/subfolder1/SampleFile.docx` physically existing in that location? what happens when change the extension a bit like `http://companyfiles.mywebsite.com/18/RepZio/companyfiles/subfolder1/SampleFile.docx12`? – shakib Dec 05 '13 at 13:31
  • it seems the . is my issue now – Slee Dec 05 '13 at 20:51
  • check out http://stackoverflow.com/questions/16886093/routing-a-url-with-extension-in-mvc4-wont-work-tries-to-serve-up-static-file – shakib Dec 06 '13 at 02:50
  • I found that last night shakib and that did solve my problem, it was a combo of solutions that you suggested that worked - put it together in a nice clean answer so I can accept it – Slee Dec 06 '13 at 12:54

1 Answers1

1

1. The file path info can be caught by a wild card matching pattern, like

url: "{id}/{dropboxfolder}/companyfiles/{*path}",

2. In ASP.net Classic mode URL with extension are served by Static file handler. To make all url go through ASP.net pipeline in Integrated mode, the following should be added in system.webserver.handlers section

<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true" />
<handlers>
  <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
  <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
  <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
  <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
  <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
  <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>

This should put the urls with extension through asp.net pipeline.

Regards

shakib
  • 5,449
  • 2
  • 30
  • 39