0 Comments

I have finished migrating from an “old” virtual private server (VPS) running Windows Server 2008 to a server running 2012 r2 which includes IIS 8.5

At this time the 1.9.1 is the latest https://github.com/Lone-Coder/letsencrypt-win-simple/releases

After extracting the zip you need to move the content to a permanent folder from where you can keep running the Automated Certificate Management Environment (ACME) which can renew the certificates

 

image

If you run it as admin, it will ask you for your e-mail. It will stay private, it’s just to notify if a renewal failed.

Will you agree on https://letsencrypt.org/documents/LE-SA-v1.1.1-August-1-2016.pdf

next is a list, not of the websites but the bindings. Mine was rather big (100 entries) and contained multiple pages. After the bindings there are more options:

image

 

After selecting a “website” number you can specify the user which will be used to run the renewal process.

The last step is to make an entry in your calendar to verify that the renewal succeeded.

I have also installed Certify to view the certificates http://certify.webprofusion.com/ 

I used version Alpha V0.9.85

All that was left was to test the website with https and if it succeeds, make an IIS redirect to route all traffic to the https version:

image

image

Good luck and enjoy the free SSL certificates!

Pin on pinterest Plus on Googleplus Post on LinkedIn
0 Comments
  •   Posted in: 
  • IIS

It has been a while since my last blog. But here is a small snippet to redirect traffic to an other place. I needed it because we have 2 domains on shared hosting. Both containing mail accounts. I could not simply add a hostheader for the 2nd domain, because it would remove all mail accounts. So I used this web.config file:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="Domein doorsturen naar andere website" stopProcessing="true">
          <match url="(.*)" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="^(?:www.)olddomain\.com$" />
          </conditions>
          <action type="Redirect" url="http://www.newdomain.com/{R:1}" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

 

ps. I used precode from codeplex to insert the xml code in an open live writer post. 0.6.0.0

Pin on pinterest Plus on Googleplus Post on LinkedIn
6 Comments
  •   Posted in: 
  • IIS

For this small article, I assume that you have an Asp.Net web application running on IIS and that you have setup your SSL certificate. So navigating to https://www.yoursite.com works. This blog post will explain how to redirect all http traffic to https in several easy steps.

1. Get the Web Platform Installer (it’s free!) from Microsoft  http://www.microsoft.com/downloads/en/details.aspx?FamilyID=32b0dfe5-f139-4e1c-b412-3da39f50bbf9 

2. After you have opened the WebPI (Web Platform Installer) search for: Rewrite

image

3. Install the component! [more]

4. Open your web.config (I used notepad++ )

5. Merge this into your web.config:

<configuration>    
    <system.webServer>
        <rewrite>
            <rules> 
                <rule name="Force HTTPS" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions>
                        <add input="{HTTPS}" pattern="off" ignoreCase="true" />
                    </conditions>
                    <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

 

And your done, when you hit save. The IIS will restart if the web.config is modified, so the new rule is now enabled!

kick it on DotNetKicks.com Shout it

Pin on pinterest Plus on Googleplus Post on LinkedIn
1 Comments

imageThis blog post is about how I used URL rewriting for a better organic search ranking. Maybe it helps out some other people who struggle to rewrite URL’s without components like URL Rewriter. It’s open source but it uses regular expressions in a configuration file. That is a more common way to rewrite, but that would make me rewrite a lot of code, because of the URL’s I have at the moment. And since developers are lazy efficient, we tend to try an other approach first.

My current URL’s are:

www.mydomain.com/product_details.aspx?id=1

www.mydomain.com/product_details.aspx?id=2

Product id 1 can be a car like Audi R8 and ID 2 can be a book like Harry Potter. Other solutions are based on URL’s like:

www.mydomain.com/product_details.aspx?name=harry%20potter

Which can be rewritten easily with a regular expression and the open source rewriting mentioned before. Here is how I solved it for my situation:

[more]

My project was recently auto migrated to asp.net 4.0 by opening the solution file in Visual Studio 2010. Which worked perfectly by the way. The Web server which has to run the project was Windows Server 2008 R2. because it was the R2 it contained IIS7.5

The first thing I had to do was installing the Microsoft web platform installer on the Web server

After that I could install the URL Rewrite module for IIS. it’s free and available on IIS.net (really recommended download!):

http://www.iis.net/download/URLRewrite

URL rewrite option in IIS

When I installed the same module on IIS7.0 (instead of 7.5) it somehow didn’t had as much preset rule templates. But on 7.5 I had the following:

Rule template of the URL rewrite component in IIS

I used the append or remove trailing slash to get this URL:

http://www.mydomain.com to rewrite to http://www.mydomain.com/

The next was cannibalize the domain name so that:

http://mydomain.com rewrites to http://www.mydomain.com

After doing that the only thing left was the part that I started this blog with: rewriting the product_details.aspx?id=1 to http://www.mydomain.com/the-fat-Audi-R8/ or the http://www.mydomain.com/harry-potter-book-1/

Therefore you need to map IIS requests to the asp.net worker process. otherwise IIS would handle the requests and now it will send the request to the asp.net process to handle it.

you have to open the web.config file and set:

<modules runAllManagedModulesForAllRequests="true" />

image

So after setting that web.config so that asp.net will handle the http requests you can start to make your project rewrite the URL’s

You need to start in the Global.asax file.

void Application_BeginRequest(object sender, EventArgs e) 
{
    string pathAndQuery = Request.Url.PathAndQuery.ToString().ToLower();

    if (!pathAndQuery.Contains(".")) // it's extensionless remember ;)
    {
        Hashtable htSite = Util.GetHashTable();
        pathAndQuery = System.Web.HttpUtility.UrlDecode(pathAndQuery); // for german things which have umlauts in it
        if (htSite[pathAndQuery] != null)
            HttpContext.Current.RewritePath(htSite[pathAndQuery].ToString(), false); // if you leave out the optional boolean, you will break your .net theme's
    }
}

In my Util class, I have this GetHashTable method which get’s stuff from the database and stores it in the Hashtable which I add to the Cache after it’s generated and filled.

public static class Util
{
    public static Hashtable GetHashTable()
    {
        Hashtable ht = (Hashtable)System.Web.HttpRuntime.Cache.Get("hturlrewrite");

        if (ht == null)
        {
            ht = new Hashtable();
            
            DataTable dt = GetYourUrlsMethod(); // your version

            foreach (DataRow dr in dt.Rows)
            {
                string value = "/Category.aspx?catg=" + dr["CategoryGroupID"];
                string categoryName = dr["CategoryGroupName"].ToString();
                categoryName = categoryName.Replace(" ", "-").ToLower(); // a dash is better for SEO then an underscore and a plus is not allowed by default in IIS

                string key = "/" + categoryName + "/";
                if(!ht.ContainsKey(key))
                {
                    ht.Add(key, value);
                }
            }
           
            System.Web.HttpRuntime.Cache.Add("hturlrewrite", ht, null, System.DateTime.Now.AddHours(24), System.TimeSpan.Zero, System.Web.Caching.CacheItemPriority.Normal, null);  
        }   
        return ht;
    }


Please do not forget to Cache this. because otherwise it would fire for each page request and access the database for building the Hashtable.

Well that is it for my implementation of URL rewriting in Asp.net 4.0 with IIS7.x with custom rewriting logic.

Good luck!

Edit: I recently encountered invalid viewstate errors. Here is how I fixed it: http://stackoverflow.com/questions/3854999/invalid-viewstate-when-using-rewritepath


kick it on DotNetKicks.com Shout it

Pin on pinterest Plus on Googleplus Post on LinkedIn