Avinash
Avinash

Reputation: 2183

Stop browser from showing javascript and CSS files from the azure app service

I am using ASP.Net MVC to develop my website

I have hosted my website on Azure and my website url is like "https://myazurewebsite.azurewebsites.net". I have a login page to my website, without login they can not browse any of my Views.

But if i use URL like https://myazurewebsite.azurewebsites.net/js/myJS.js, then browser is rendering my js file. I don't want to show my JS files to unauthorized users.

I there any way to stop this through configuration or through code?

Upvotes: 1

Views: 592

Answers (1)

Avinash
Avinash

Reputation: 2183

I have solved this issue by adding below lines in my web.config.

<security>
      <requestFiltering>
        <filteringRules>
          <filteringRule name="protectjs" scanUrl="true" scanQueryString="true">
            <scanHeaders>
              <clear />
              <add requestHeader="Accept" />
            </scanHeaders>
            <appliesTo>
              <clear />
              <add fileExtension=".js" />
              <add fileExtension=".css" />
            </appliesTo>
            <denyStrings>
              <clear />
              <add string="text/html" />
            </denyStrings>
          </filteringRule>
        </filteringRules>
      </requestFiltering>
    </security>

Upvotes: 2

Related Questions