No More Broken Links

On November 16, 2016, in How-to, Technical, by Ray

Ray HuangAre broken links affecting the SEO score and ranking of your website? Fear not, because there is a tool available to you on DiscountASP.NET which can easily fix that problem and help you move your site to the top.

It’s done by setting up custom rewrite providers through the URL Rewrite module which store rewrite/redirect mappings in either an SQL database or text file. In this article I will show you how to set them up.

There are 3 types of providers available for you to use (DbProvider, FileMapProvider, and FileContainsProvider). The DbProvider is used to retrieve mappings from an SQL database, the FileMapProvider is used for a text file, and the FileContainsProvider is used to check if a list of strings in a text file are part of a sub-string in the provider’s input string. Applications for its use include blocking robots or redirecting multiple domain names to a single one.

  • To start configuring any of the providers, launch IIS Manager and double click on the URL Rewrite module icon.

urlrewriteicon

  • Click on the View Providers… link under Manage Providers to your right.

viewproviders

  • Then click on the Add Provider… link to your right.

addprovider

  • In the Add Provider window, enter a name and select the provider you want to use in the Managed Type drop-down list. Click on the OK button to save the setting.

addproviderwindow

Configuring the DbProvider Example

In order to use the DbProvider, you’ll need to order a Microsoft SQL Server add-on database. After purchasing the add-on, log into your database using SQL Server Management Studio. Create a table using the Table Designer (GUI) with 2 columns of data type nvarchar that are not null.

table

Or execute the following script in a New Query window:

CREATE TABLE [dbo].[RewriteTable](
[OriginalUrl] [nvarchar](256) NOT NULL,
[NewUrl] [nvarchar](256) NOT NULL
)

The table name and columns are arbitrary (you can call them anything you want as long as they make sense to you). It’s not important in setting up the provider, but you’ll also need to create a stored procedure using the following code:

CREATE PROCEDURE [dbo].[GetRewrittenUrl] 
@input nvarchar(256)
AS
SELECT rt.NewUrl 
FROM dbo.RewriteTable rt 
WHERE rt.OriginalUrl = @input

The name of the stored procedure is what is important as it must match when you setup the provider. If you created your own custom columns, remember that they need to match in your stored procedure.

Now go back into IIS Manager, navigate to the Rewrite Providers section (i.e. follow the steps in the first section above to the point where you add the provider), highlight it and click on the Add Provider Setting… link to your right.

addprovidersetting

In the Add Provider Setting window, you’ll need to configure 3 values. Select the Name in the drop down box and enter the following:

addprovidersettingwindow

  • SQL Server connection string – Enter the connection string found in your Control Panel without the encapsulating quotes and replacing the password mask with your actual password (e.g. Data Source=tcp:sql2k1201.discountasp.net;Initial Catalog=SQL2012_123456_sql2012;User ID=SQL2012_123456_sql2012_user;Password=election2016;) Click on OK to save the setting.
  • Stored procedure name – Enter the name of the stored procedure you created above.
  • Cache minutes interval – set it to 0 (default) if the values in your table will not change or set it to a positive number to specify a time when it will expire (used if you plan to change the rewrite maps in your table frequently)

You’ll have to do this 3 times, one for each setting. Now, in your root web.config file place the following rule in the <rewrite> section:

<rule name="DbProviderRule" stopProcessing="true">
    <match url="(.*)" />
    <conditions>
        <add input="{StoreInDb:{R:1}}" pattern="(.+)" />
    </conditions>
    <action type="Redirect" url="{C:1}" />
</rule>

Replace “StoreInDb” with the name of your provider if you chose something different. Your web.config file look something like this now:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <providers>
        <provider name="StoreInDb" type="DbProvider, microsoft.web.Iis.Rewrite.Providers, Version=7.1.761.0, Culture=neutral, PublicKeyToken=0545b0627da60a5f">
          <settings>
            <add key="ConnectionString" value="Data Source=tcp:sql2k1201.discountasp.net;Initial Catalog=SQL2012_123456_sql2012;User ID=SQL2012_123456_sql2012_user;Password=election2016;" />
            <add key="StoredProcedure" value="GetRewrittenUrl" />
            <add key="CacheMinutesInterval" value="0" />
          </settings>
        </provider>
      </providers>
      <rules>
        <rule name="DbProviderRule" stopProcessing="true">
          <match url="(.*)" />
          <conditions>
            <add input="{StoreInDb:{R:1}}" pattern="(.+)" />
          </conditions>
          <action type="Redirect" url="{C:1}" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

Make sure none of the sections are missing as they are all required to invoke the rule. That’s it. Now, you can fill your database with 1 to 1 mappings to redirect URLs. For example, say you have a deprecated product link http://www.YourHostedDomainName.com/products/index.html which you want redirected to http://www.YourHostedDomainName.com/toys/index.html, just enter “products/index.html” in the OriginalURL column and “toys/index.html” in the NewURL column of your database.

ssmsurls

When you enter the old URL in a browser, you’ll be redirected to the new one. The tool can also be used to rewrite URLs instead of redirecting them for SEO purposes. It may also come in handy if you’re not good with coming up with regular expressions for use in your URL Rewrite rules or if you find URL Rewrite difficult in general to understand. You can map everything using the database. It’s just a lot more work if you have a very large site, but it can be tremendously useful for smaller sites.

Configuring the FileMapProvider

The FileMapProvider works the same way as the DbProvider except that you are storing the URLs as a CSV (Comma Separated Value) pair in a text file. Setup the provider following the instructions in the first section of this article. Then create a text file with the mapping. For example:

products/index.html, toys/index.html

We’ll also place the text file in the /App_Data folder for security since it cannot be accessed through a web browser. Then go back to IIS Manager and configure the provider setting using the Add Provider Setting window. There is only 1 value you need to set:

  • File path – Make sure you enter the value in this way {DOCUMENT_ROOT}\App_Data\mappings.txt or use an absolute path (e.g. E:\web\username\htdocs\App_Data\mappings.txt)

For the rule in the web.config file, you can use the same rule as provided from the previous section except replace “StoreInDb” with the name of your FileMapProvider (e.g. StoreInFile).

Configuring the FileContainsProvider

The FileContainsProvider is setup in the same way as the FileMapProvider with the exception of the text file. It’s just a list of strings (text) separated by carriage returns. I mentioned a couple of use cases earlier, and I will provide you with an example of how you could apply it to your site. The following instructions work only if you have purchased the Unique IP address add-on or a couple of domain pointers. First let’s create a text file with a list of domain names (either sub-domain names or domain pointers), call it list.txt and place in it our /App_Data folder. Then setup the FileContainsProvider to point to this list.txt file. Add the following rule to your web.config file:

<rule name="FileContainsProviderRule" stopProcessing="true">
    <match url=".*" />
    <conditions>
        <add input="{FileContains:{HTTP_HOST}}" pattern=".+" />
    </conditions>
    <action type="Redirect" url="http://www.mainsite.com" />
</rule>

Try typing any of the sub-domain names or domain pointers in your list in a browser. You’ll notice all the requests will be redirected to the homepage of your main site.

 

September Updates

On September 21, 2016, in Announcements, by Ray

Ray HuangHere’s a list of our Web Application Gallery updates for September:

  • Acquia Drupal 7.50.52.6330
  • BlogEngine.NET 3.3
  • DotNetNuke (DNN) 8.0.4.226 Platform
  • Gallery Server Pro 4.0.1
  • Joomla 3.6.2
  • mediaWiki 1.27.1
  • Moodle 3.1.2
  • nopCommerce 3.80
  • Orchard 1.10.1
  • osCommerce 2.3.4 NEW
  • phpMyAdmin 4.6.4
  • SilverStripe CMS 3.4.1
  • WordPress 4.6.1
 

Ray HuangFor those who have or want to have a mixed language site (e.g. ASP.NET Core 1.0 and PHP), you might notice that your PHP applications have stopped working, and you’ll get an error message like this:

HTTP Error 502.5 – Process Failure

Untitled-1

Don’t worry.  Nothing on our server or your site is broken.  You just need to modify the web.config file a bit or create one in the appropriate directory because the AspNetCoreModule is the default handler for processing files.

I’ll show you how in this guide where I have an ASP.NET Core 1.0 application in the root and WordPress in a sub-directory.  Since I don’t want to memorize web.config markup language, I’ll let IIS Manager do most of the work for me.

Log into your site using IIS Manager and highlight the folder WordPress was installed to, so that the web.config file in that directory will get modified or created if there isn’t one.

Double click on the Handler Mappings module.

IISManager

On your right, select View ordered List…

HandlerMappings

Using the Move Up/Move Down Actions, move PHP##_via_FastCGI to the top where ## represents the PHP version number that you are using.  This will create the necessary markup in the web.config file in the WordPress directory without affecting your other web.config files.

OrderedList

Now click on View Unordered List…

Highlight aspNetCore and click on Remove.  Don’t worry, this doesn’t delete the AspNetCoreModule.  It just removes the handler mapping (i.e. entry in the web.config file), and voila, your PHP application should be working again.

 

Ray HuangNow that we have launched ASP.NET Core 1.0 on DiscountASP.NET, here is a sample tutorial on how to successfully publish an application.  First, make sure you have installed the pre-requisites on your computer to support an ASP.NET Core 1.0 application within Visual Studio.  In this guide, I am using Visual Studio 2015 Community Edition.

Preparing a Sample Application

  • Launch Visual Studio.
  • Select File -> New -> Project (CTRL-SHIFT-N)
  • Select ASP.NET Core Web Application (.NET Core), name your application and click on OK.

NewProject

  • For the ASP.NET Core Template, select Web Application and click on OK. Immediately, in the Solution Explorer window on the right hand side, a yellow pop-up window will open saying “Restoring Packages.” Wait until that finishes as the references for your application are being downloaded and added to your solution.

Template

Publishing the Application via Web Deploy

  • Log into your DiscountASP.NET Control Panel.
  • Click on the Account Info/Edit link under the Account Management section in the menu to your left.
  • Scroll all the way to the bottom and click on the Download Web Deploy Publish Settings.

DownloadPublishSettings

  • Download this PowerShell script from GitHub and place it in C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web Tools\Publish\Scripts\1.1.0\publish-module.psm1 or wherever you installed Visual Studio to (e.g. if you changed the drive letter to E:)
  • Now in Visual Studio, go to Build -> Publish appname. In the Publish window that opens, select Import.

Profile

  • Find the publish profile you downloaded earlier from our Control Panel and click on OK.

Browse

  • In the Connection section, you’ll notice the fields are already pre-populated for you. You’ll need to make a slight modification to the Server field by appending this query string:

?site=domain-name.com

Replacing domain-name.com with the domain name associated with your hosting account.  The full line should look something like this:

https://web###.discountasp.net:8172/MsDeploy.axd?site= domain-name.com

Connection

  • Click on the Validate Connection button to make sure you get a green check mark. If you don’t, you can open a support ticket to have one of our staff members recycle the Web Management Service for you.  Sometimes the Web Deploy service on the server gets “stuck” and recycling usually fixes the problem.  At this point, you can go ahead and click Publish if you want.  Clicking on Next will allow you to further refine some configuration settings before deploying.

Tips/A Few Things to Note

  • Publishing to a sub-directory does not work at this time. That should be fixed in an upcoming update.
  • If you’re having trouble publishing, double check that your antivirus/firewall is not blocking port 8172.
  • ASP.NET Core 1.0 is only supported on our newer Windows 2012 R2 servers. If your hosting account is not on this platform, please open a support ticket to have it migrated.  The migration process takes about 30 minutes unless you have a large number of files.
  • If you’re having trouble getting your ASP.NET Core 1.0 application to work and don’t know where to begin to debug, make sure you enable error logging in the web.config file. Change the stdoutLogEnabled to “true” and create the directories that will store the log (e.g. “.\logs\stdout”).  It is not enabled by default.

If all goes smoothly, your site will look something like this:

AspNetCoreSampleApp

 

Ray HuangWith the launch of SQL Server 2016, one of the new features you might be interested in is Stretch Databases.  It’s basically a data archiving feature which will move your data from your current SQL database to an Azure SQL database for storage, while still allowing the archived data to be queried.

It’s a great idea if you have a very large and growing database and need to keep a history of that data for use later.  A perfect example would be a customer orders table.  I won’t go in to detail on how to set it up as there is already a great guide on Microsoft for getting started, but I just wanted to highlight some of the pros and cons (in my opinion) of utilizing it:

Pros:

  • Great for very large and growing databases as it frees up space on your current SQL server database to record new data.
  • Azure automatically backs up databases on its platform by taking snapshots every 8 hours and retains them for 7 days providing you with a range of restore points.
  • Azure databases are geo-redundant and replicated several times to reduce the risk of data loss.
  • Stretch databases utilize staging tables when moving data to Azure, providing an additional point of redundancy.

Cons:

  • Limitations on data that can be stretch-enabled.
  • Costs incurred for storing data.  (This could potentially be a pro if you are currently paying a high price for data storage.)
  • Backups made on stretch enabled databases are shallow backups (i.e. they do not contain the migrated data), and in order to retrieve the data, your database will have to be large enough to accommodate the reverse transfer which also incurs a transfer cost.

In summary, it’s a great idea for a business sites which conduct a lot of business, but maybe not so great for your personal website or blog.

 

Ray HuangBack in August 2015, I wrote an article which showed how you could deploy an ASP.NET 5 application on our servers for those who wanted to try and test it out.  I also mentioned in the same article that because ASP.NET 5 was still in beta, what I wrote may or may not work for future releases.

I can now say they are no longer applicable.  They will still work for Beta6 but not for RC1 or RC2.  This article covers some of the changes made since Beta6 and why we chose not to support RC1.  ASP.NET 5 (vNext) has also been renamed to ASP.NET Core 1.0, and I’ll refer to it as such from now on.

We chose not to support RC1 for a couple of reasons.  In order deploy an RC1 application successfully, some changes need to be made on the back end.  RC1 requires the installation of an additional IIS module, the HTTPPlatformHandler.  It’s a pretty interesting module which allows you to run non-native Windows languages such as Java, Node.exe, Ruby, etc. under IIS.

But that wasn’t the main reason we chose not to support RC1.  RC1 just presented some technical challenges to overcome, mainly with how the file directory is setup and security (i.e. approot and wwwroot).

Since ASP.NET Core represents a paradigm shift in the way ASP.NET apps were being developed, integrating it with our current infrastructure while providing backwards compatibility for older versions of ASP.NET proved difficult.

There was also the problem with getting Web Deploy/FTP from Visual Studio working correctly which many of our current customers are familiar with and rely on to deploy their websites.  Since this was just a Release Candidate, we adopted a wait and see approach to see what further changes would be made to the product.

Fast forwarding to May 2016, that proved to be a wise decision.  RC2 helps address many of the issues we faced trying to integrate RC1 in our environment.  It no longer requires the HttpPlatformHandler in order to run, but instead relies on a new module, ASPNetCoreModule, developed specifically for Core and can be enabled with the addition of one line in your web.config file.

If you also examine the file structure of an RC2 application, you’ll also notice some major changes.  The approot folder is now gone, but the assemblies, runtimes, and configuration files are still stored outside of the wwwroot directory (either one file directory level above or adjacent to it).

What this means for us is that we no longer have to make changes to our file directory structure to accommodate/fix deployment and security issues such as the one mentioned in my previous article if you want to host the application in the root of your account.  RC2 applications can now be deployed the same way as any other type of application (e.g. MVC, web forms, etc.)

We’ve also been working directly with Microsoft to get Web Deploy working, and I can now say it’s possible to use Web Deploy to deploy an RC2 application with a few minor modifications to Visual Studio and your solution’s publishing profile.   Web deployment now looks and feels like what you’re used to.

We still have some testing to perform before we can roll this out to production, such as integrating the .NET Core Framework in order to support portable applications as opposed to self-contained applications, but you can rest assured that when we do, you’ll also have the technical expertise of a knowledgeable staff to help you get your ASP.NET Core application running on our servers.

 

May Updates

On May 5, 2016, in Announcements, by Ray

Ray HuangHere’s a list of our Web Application Gallery updates for May:

  • Acquia Drupal 4.43.49.6309
  • DotNetNuke (DNN) 8.0.1.236 Platform
  • Gallery Server Pro 4.0.0
  • Joomla 3.5.1
  • Kentico 9
  • mojoPortal 2.4.1.0
  • Moodle 3.0.3
  • Orchard 1.10
  • phpBB 3.1.9
  • phpMyAdmin 4.6.0
  • SilverStripe CMS 3.3.1
  • WordPress 4.5
 

February Updates

On February 4, 2016, in Announcements, by Ray

Ray HuangHere’s a list of our Web Application Gallery updates for February:

  • BlogEngine.NET 3.2
  • DotNetNuke (DNN) 7.4.2 Platform
  • Joomla 3.4.8
  • Moodle 3.0.1
  • nopCommerce 3.70
  • Orchard 1.9.2
  • phpMyAdmin 4.5.3.1
  • SilverStripe CMS 3.2.1
  • Umbraco 7.3.4
  • WordPress 4.4
 
iBlog by PageLines