Last active
February 26, 2020 11:19
-
-
Save ankittyagii/ad4df60173e13b389ec2bf1e7a766979 to your computer and use it in GitHub Desktop.
Prevent From Hotlinking in IIS/ASP.NET Framework/ASP.Net Core Application
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ItemGroup> | |
<None Update="hotlinkingURLRewrite.xml"> | |
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | |
</None> | |
</ItemGroup> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<rewrite> | |
<rules> | |
<rule name="Prevent Image Hotlinking"> | |
<match url=".*\.(jpg|doc)$"/> | |
<conditions> | |
<add input="{HTTP_REFERER}" pattern="^http://demo.com/.*$" negate="true"/> | |
</conditions> | |
<action type="Rewrite" url="/images/block.jpg"/> | |
</rule> | |
</rules> | |
</rewrite> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
public configure ()..{ | |
using (var urlRewriteStreamReader = File.OpenText("UrlRewrite.xml")) | |
{ | |
var options = new RewriteOptions().AddIISUrlRewrite(urlRewriteStreamReader); | |
app.UseRewriter(options); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<rewrite> | |
<rules> | |
<rule name="Prevent Image Hotlinking"> | |
<match url=".*\.(jpg|doc)$"/> | |
<conditions> | |
<add input="{HTTP_REFERER}" pattern="^http://demo.com/.*$" negate="true"/> | |
</conditions> | |
<action type="Rewrite" url="/images/block.jpg"/> | |
</rule> | |
</rules> | |
</rewrite> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment