Showing posts with label Web.config. Show all posts
Showing posts with label Web.config. Show all posts

Thursday, August 07, 2014

How to enable browser compatibility mode for your website

After every browser major release there will be something's which always mess up. Can’t say its always but it has happened so far :- )

So you might asked to force to the stable version of the browser to make sure your web application renders well in the browser. Here are some things we can add to existing page to make sure it works in the compatible mode by forcing the version we would like to render.

Method 1: If its at page level.

<head>
<!-- Mimic Internet Explorer 9 -->
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE9" >
<title>My webpage</title>
</head>



Method2: You can do the same globally in web.config by adding code like below


<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<httpProtocol>
<customHeaders>
<clear />
<add name="X-UA-Compatible" value="IE=EmulateIE9" />
</customHeaders>
</httpProtocol>
</system.webServer>
</configuration>


The value attribute is used to set the default render engine to render page. If you are looking for IE8 compatibility use the following code


<add name="X-UA-Compatible" value="IE=EmulateIE8" />


we can also use this tag


<add name="X-UA-Compatible" value="IE=Edge" />


IE=edge indicates that IE should always use its latest rendering engine to render the page. This should ensure the page is rendered consistently with other browsers and in a standards-compliant manner


The following is the documentation that I've used to try understand how IE decides to actually trigger the compatibility mode.

http://msdn.microsoft.com/en-us/library/ff406036%28v=VS.85%29.aspx

http://blogs.msdn.com/b/ie/archive/2009/02/16/just-the-facts-recap-of-compatibility-view.aspx

Tuesday, January 31, 2012

How to add MIME types in Web.config on hosted Servers, Go Daddy, IIS 7 etc.

Ever wanted to add a custom mime type to your Web server?  I ran into this issue the other day when I tried to serve up .otf files related to fonts on my Web server and  I got this error: 404.3 error - mime type missing!

Thankfully, adding mime types is easier than ever thanks to the all-new distributed configuration option, which allows for IIS7 configuration to be stored in web.config files, along with asp.net configuration, to be deployed with your content. 

I'll show how easy it is to add mime types to your Web server.  This method will work on any IIS7 web server, and it will be ignored on all non-IIS7 web servers, so it should be safe to do no matter the type of application or content.  Since the <staticContent> section is delegated by default, the configuration snippets below should 'just work' on all IIS7 Web sites. 

  1. Open or edit the web.config in your site home directory.
  2. Add the following section in configuration section under web server.
<system.webServer>   
    <staticContent>
      <mimeMap fileExtension=".otf" mimeType="font/otf" />
    </staticContent>
</system.webServer>

This works even on Go Daddy hosted server also. You can add as many file times you want allow in this static content section.  For example these few MIME types you can add if you want on your Web server

<mimeMap fileExtension=".m4v" mimeType="video/m4v" />
<mimeMap fileExtension=".ogg" mimeType="audio/ogg" />
<mimeMap fileExtension=".oga" mimeType="audio/ogg" />
<mimeMap fileExtension=".ogv" mimeType="video/ogg" />
<mimeMap fileExtension=".webm" mimeType="video/webm"/>
<!-- For silverlight applicaitons -->
<mimeMap fileExtension=".xaml" mimeType="application/xaml+xml" />
<mimeMap fileExtension=".xap" mimeType="application/x-silverlight-app" />
<mimeMap fileExtension=".xbap" mimeType="application/x-ms-xbap" />

Hope this helps Thumbs up

Tuesday, May 17, 2011

Web.config transformations in .NET 4.0

The web.config has now been refactored, and with ASP.Net 4 a lot of the settings that were previously found in the web.config file have now been moved to the machine.config file. This significantly reduces the size of the file, which I think is a great bonus.

Web.config transformations cater for moving your application between your relevant environments (e.g. DEV, QA, PROD). The transformations work on the relevant configurations you setup.
To create your own Configuration build with configuration transformations, create a new ASP.NET Web Application in Visual Studio 2010. Next, in the menu select "Build" and then "Configuration Manager". In the "Active Solution Configuration" drop down, select "New". Name the relevant configuration, for example I'm calling mine "DEV" and copying the settings from the "Debug" configuration.

Make sure "Create new project configurations" is selected. Once you click okay, you will see your Web.config file now has a "+" next to it in your solution explorer.

If you don't see the "+", build you solution, right click the web.config file and select "Add Config Transformations".
You will see for each of your build configurations there will be a "Web.[Build Configuration Name].config" file. If you open any of these files, you will see place holders for different sections of your original web.config file.

To change settings per your relevant build configuration, check out the following MSDN Article:Web.config Transformation Syntax for Web Application Project Deployment

Hope this helps.

Thursday, January 13, 2011

How to update Web.config dynamically?

I need to update web.config dynamically? So this is what I did, this code below has done the trick for me.

string value = "webmaster@company.com";
Configuration config = webConfigurationManager.OpenWebConfiguration("~");
AppSettingsSection appsetting = config.GetSection("appSettings");
appsetting.Settings("fromAddress").Value = value;
config.Save();
Make sure to add System.Web.Configuration in the namespace. Have fun Light bulb

Thursday, January 06, 2011

assemblyBinding: Using Shared DLLs in .NET

How to Share DLLs in VS 2010. Recently I and my team had a problem working with a Shared DLL. Our developers are saving our project in different locations of our computer. Few are saving in D drive and few in E drive. So while getting latest solution from the Visual source safe some of us are having missing references problem with the DLLs when we have Shared DLLs in a location. So to resolve this we have created a folder in *\bin folder with name Shareddlls and placed all the Shared dls in that folder.

Once we have done this we need to add piece of code in web.config.

 <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <probing privatePath="bin;bin/shareddlls" />
    </assemblyBinding>
  </runtime>

This worked perfectly for me. Microsoft rocks. When I first read that .NET assemblies could be "redirected" at runtime, I was stunned and a little bit suspicious. By using Assembly Binding Redirection you can redirect an assembly binding reference to another version of an assembly by using entries in the application or machine configuration files. You can redirect references to .NET Framework assemblies, third-party assemblies, or assemblies of your own application. Each version of the .NET Framework has a machine configuration file, and any redirection information in that file affect all applications running under that version of the .NET Framework.


Redirecting .NET Framework Assembly Binding


The .NET Framework assembly unification model treats all .NET Framework assemblies of a given version, and the runtime of that version, as a single unit. The redirections that occur with this model are the default behavior for the runtime.
There are several ways to instruct the runtime to load a .NET Framework assembly with a different version than that of the loaded runtime:



  • Add settings in the application configuration file.

  • Add settings in the machine configuration file.

  • Create a publisher policy file that is distributed with a component to specify which assemblies a component should use.

A binding redirection in an application configuration file for a unified .NET Framework assembly cancels the unification for that assembly. To redirect an assembly binding reference for an assembly that is not part of the .NET Framework, specify the binding redirection information in the application configuration file using the <assemblyBinding> element.