Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I've gone with the following solution in the past when I've not been able to modify IIS settings.</p> <p>Either in an HTTPModule (probably cleanest), or global.asax.cs in Application_BeginRequest or in some BasePage type event, such as OnInit I perform a check against the requested url, with a known string I wish to be using:</p> <pre><code>public class SeoUrls : IHttpModule { #region IHttpModule Members public void Init(HttpApplication context) { context.PreRequestHandlerExecute += OnPreRequestHandlerExecute; } public void Dispose() { } #endregion private void OnPreRequestHandlerExecute(object sender, EventArgs e) { HttpContext ctx = ((HttpApplication) sender).Context; IHttpHandler handler = ctx.Handler; // Only worry about redirecting pages at this point // static files might be coming from a different domain if (handler is Page) { if (Ctx.Request.Url.Host != WebConfigurationManager.AppSettings["FullHost"]) { UriBuilder uri = new UriBuilder(ctx.Request.Url); uri.Host = WebConfigurationManager.AppSettings["FullHost"]; // Perform a permanent redirect - I've generally implemented this as an // extension method so I can use Response.PermanentRedirect(uri) // but expanded here for obviousness: response.AddHeader("Location", uri); response.StatusCode = 301; response.StatusDescription = "Moved Permanently"; response.End(); } } } } </code></pre> <p>Then register the class in your web.config:</p> <pre><code>&lt;httpModules&gt; [...] &lt;add type="[Namespace.]SeoUrls, [AssemblyName], [Version=x.x.x.x, Culture=neutral, PublicKeyToken=933d439bb833333a]" name="SeoUrls"/&gt; &lt;/httpModules&gt; </code></pre> <p>This method works quite well for us.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload