Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Hosted-services / Azure

Enabling Frame Redirection in Azure

0.00/5 (No votes)
24 Nov 2016CPOL 6.3K  
This little tip is about how to enable Frame Redirection when using Azure App Services

Introduction

This little tip is about how to enable "Frame Redirection" when using Azure App Services. You can obtain more information about what redirection is by clicking here.

The Problem

I came across this problem when I registered a new domain. I wanted to redirect that domain using "Frame Redirection" to return my personal site in Azure. So, the redirection wasn't working because Azure adds by default (or at least I think so) an "X-FRAME-OPTIONS" header with a "SAMEORIGIN" value. This means that, by default, "Frame redirection" is not allowed.

The Solution

To solve the problem, you just need to add this little piece of code to your Global.asax file:

C#
private void Application_EndRequest(object sender, EventArgs e)
{
   Response.Headers["X-FRAME-OPTIONS"] = "ALLOW-FROM url1,url2;
}

As you can see above, "X-FRAME-OPTIONS" header is replaced with the keyword "ALLOW-FROM" and the list of authorized urls delimited by commas. By doing this, I solved the problem and the redirection is working properly now.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)