Showing posts with label Go Daddy. Show all posts
Showing posts with label Go Daddy. Show all posts

Tuesday, February 07, 2012

Redirect HTTP to HTTPS in ASP.NET

Recently I got to do this when one of our site was hosted on Go Daddy Hosted Server. They don’t have SSL redirect functionality for Windows environment, so we need to write some script to support this.

I have done something like this by writing few lines of code in Global.asax file in your web project.

void Application_BeginRequest(Object sender, EventArgs e)
{
if (ConfigurationManager.AppSettings["APIEnvironment"].ToUpper() == "LIVE"
&& Request.ServerVariables["HTTP_HOST"].ToString().ToLower().Trim() != "localhost") // turn the mode OFF in development
{
if (HttpContext.Current.Request.IsSecureConnection.Equals(false))
{
Response.Redirect("https://" + Request.ServerVariables["HTTP_HOST"] + HttpContext.Current.Request.RawUrl);
}
}
}

Hope this helps. Coffee cup

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