Developer forum

Forum » Development » Content-Disposition for files

Content-Disposition for files

Peter Bille Larsen
Reply

Hi DWs

 

Is it possible to set Content-Disposition for some files?

 

.hex, .bin

 

its making some problems for a client that the browser sets the files as zip files.

 

//Bille


Replies

 
Nicolai Høeg Pedersen
Reply
This post has been marked as an answer

You can from web.config:

 

http://serverfault.com/questions/320450/conditionally-set-content-disposition-header

 

But you cannot be sure it always works. IE i.e. will serve .png as image no matter what you send out.

 

Nicolai

Votes for this answer: 1
 
Peter Bille Larsen
Reply

cool thanks!
thats ok, I think that's the best we can do :-)

 

//Peter Bille

 

 

 
Peter Bille Larsen
Reply

Nic, where should I put the rewrite section without messing up dynamicweb?

Just below   </system.serviceModel> before </configuration> ends?

 
Nicolai Høeg Pedersen
Reply

Just put it in the node structure below. You probably have system.webserver node already, add the rewrite node and add your outboundrules node inside the rewrite node. 

 

<configuration>
  <system.webServer>
    <rewrite>
 
Peter Bille Larsen
Reply

Hi Nicolai.

 

I have put this together to the rewrite. Do you notice any problems?

 

     <rewrite>
    <outboundRules>
    <rule name="download hex filer" preCondition="ErHex">
    <match serverVariable="RESPONSE_Content-Disposition" pattern=".*" />
    <conditions>
    <add input="{REQUEST_FILENAME}" pattern="(.*)\\([^/]+)\.hex$" />
    </conditions>
    <action type="Rewrite" value="attachment; filename={C:2}.hex" />
    </rule>
    <preConditions>
    <preCondition name="ErHex">
    <add input="{REQUEST_FILENAME}" pattern="\.hex$" />
    </preCondition>
    </preConditions>
    </outboundRules>



    <outboundRules>
    <rule name="download bin filer" preCondition="ErBin">
    <match serverVariable="RESPONSE_Content-Disposition" pattern=".*" />
    <conditions>
    <add input="{REQUEST_FILENAME}" pattern="(.*)\\([^/]+)\.bin$" />
    </conditions>
    <action type="Rewrite" value="attachment; filename={C:2}.bin" />
    </rule>
    <preConditions>
    <preCondition name="ErBin">
    <add input="{REQUEST_FILENAME}" pattern="\.bin$" />
    </preCondition>
    </preConditions>
    </outboundRules>


    </rewrite>

 

 
Nicolai Høeg Pedersen
Reply

It seems ok. But notice I have not tried this at home!

 

Also make sure you merge these configurations into one Ouboundrules node.

 

BR Nicolai

 
Peter Bille Larsen
Reply

ok like this.

 

 

 

<rewrite>
<outboundRules>
<rule name="download hex filer" preCondition="ErHex">
<match serverVariable="RESPONSE_Content-Disposition" pattern=".*" />
<conditions>
<add input="{REQUEST_FILENAME}" pattern="(.*)\\([^/]+)\.hex$" />
</conditions>
<action type="Rewrite" value="attachment; filename={C:2}.hex" />
</rule>
<preConditions>
<preCondition name="ErHex">
<add input="{REQUEST_FILENAME}" pattern="\.hex$" />
</preCondition>
</preConditions>
 
 

<rule name="download bin filer" preCondition="ErBin">
<match serverVariable="RESPONSE_Content-Disposition" pattern=".*" />
<conditions>
<add input="{REQUEST_FILENAME}" pattern="(.*)\\([^/]+)\.bin$" />
</conditions>
<action type="Rewrite" value="attachment; filename={C:2}.bin" />
</rule>
<preConditions>
<preCondition name="ErBin">
<add input="{REQUEST_FILENAME}" pattern="\.bin$" />
</preCondition>
</preConditions>
</outboundRules>
 
 
</rewrite>
 
Nicolai Høeg Pedersen
Reply

Yes.

 

Your website will tell you if it is wrong :-)

 
Peter Bille Larsen
Reply

cool thanks :-)

 

You must be logged in to post in the forum