Current Topic: Microsoft

0

Posted by Michael Alfaro on February 6, 2012

IIS7 URL Rewrite Module – User Friendly URLs

If you’re looking to write User friendly URLs off of IIS7, the rewrite module has a simple template to help you achieve it.  Here’s the source: http://learn.iis.net/page.aspx/497/user-friendly-url—rule-template/

“Using rule template to generate rewrite rules

The “User Friendly URL” rule template can be used to generate rewrite, redirect and outbound rules that make URLs for your dynamic web application more user and search engine friendly. Typically, dynamic web pages take into account query string parameters when generating an output HTML. The URLs with query strings (e.g. http://contoso.com/articles.aspx?year=2008&month=11) are not as easy for humans to use and communicate as simple hierarchy based URLs (e.g. http://contolso.com/articles/2008/11). In addition some search engine crawlers may ignore the query string when indexing the web site pages. The rule template helps you generate rewrite rule that transform the hierarchy based URLs to URLs with query strings. The templace can also, optionally, generate a redirect rule that can be used to redirect web clients form URLs with query strings to clean URLs. Finally, it is possible to create an outbound rewrite rule that replaces all the occurrences of URLs with query strings in the HTML responce with their hierarchy based URL equivalents.

To use the template follow these steps:

  1. Go to IIS Manager
  2. Select “Default Web Site”
  3. In the Feature View click “URL Rewrite“


  4. In the “Actions” pane on right hand side click on “Add rules…” and then select “User Friendly URL” template:


  5. In the “Add rules to enable user friendly URLs” dialog enter an example of an URL with query string parameters: http://localhost/article.aspx?id=123&title=some-title and then expand the drop down list with suggested options for how that example URL can be transformed into a URL without query string.



  6. Choose the second option: http://localhost/article/123/some-title. Notice that the URL pattern and Substitution URL have been updated accordingly. These will be used in the rewrite rule that will be created by the rule template. Check the “Create corresponding redirect rule” to create a redirect rule that will be used, when web clients used internal URL to request a web page. Those clients will be redirected to a corresponding public URL.
    Also, check the “Create corresponding outbound rewrite rule” to create an outbound rule that will replace all instances of internal URLs in the response HTML with their public equivalents.


  7. Click “OK” so that the rewrite, redirect and outbound rules will be generated:”


Topics: , ,

0

Posted by Michael Alfaro on February 2, 2012

Making your site SEO friendly with IIS7 and URL Rewriter module

Have this bookmarked for reference purposes.  I do refer back to this article every once in a while, so I figured I should share.  Here’s the source: http://blogs.msdn.com/b/carlosag/archive/2008/09/02/iis7urlrewriteseo.aspx

Shout-out to CarlosAg for posting this:

“1) Canonicalization

Basically the goal of canonicalization is to ensure that the content of a page is only exposed as a unique URI. The reason this is important is because even though for humans it’s easy to tell that http://www.carlosag.net is the same as http://carlosag.net, many search engines will not make any assumptions and keep them as two separate entries, potentially splitting the rankings of them lowering their relevance. Another example of this is http://www.carlosag.net/default.aspx and http://www.carlosag.net/. You can certainly minimize the impact of this by writing your application using the canonical forms of your links, for example in your links you can always link to the right content for example: http://www.carlosag.net/tools/webchart/ and remove the default.aspx, however that only accounts for part of the equation since you cannot assume everyone referencing your Web Site will follow this carefully, you cannot control their links.

This is when URL Rewrite comes into play and truly solves this problem.

Host name.

URL Rewrite can help you redirect when the users type your URL in a way you don’t unnecessarily want them to, for example just carlosag.net. Choosing between using WWW or not is a matter of taste but once you choose one you should ensure that you guide everyone to the right one. The following rule will automatically redirect everyone using just carlosag.net to www.carlosag.net. This configuration can be saved in the Web.config file in the root of your Web Site.Note that I’m only including the XML in this blog, however I used IIS Manager to generate all of these settings so you don’t need to memorize the XML schema since the UI includes several friendly capabilities to generate all of these..

<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name=”Redirect to WWW” stopProcessing=”true”>
<match url=”.*” />
<
conditions>
<add input=”{HTTP_HOST}” pattern=”^carlosag.net$” />
</
conditions>
<action type=”Redirect” url=”http://www.carlosag.net/{R:0}” redirectType=”Permanent” />
</
rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

Note that one important thing is to use Permanent redirects (301) , this will ensure that if anybody links your page using a non-WWW link when the search engine bot crawls their Web Site it will identify the link as permanently moved and it will treat the new URL as the correct address and it will not index the old URL, which is the case when using Temporary (302) redirects. The following shows how the response of the server looks like:

HTTP/1.1 301 Moved Permanently
Content-Type: text/html; charset=UTF-8
Location: http://www.carlosag.net/tools/
Server: Microsoft-IIS/7.0
X-Powered-By: ASP.NET
Date: Mon, 01 Sep 2008 22:45:49 GMT
Content-Length: 155<head><title>Document Moved</title></head>
<body><h1>Object Moved</h1>This document may be found <a HREF=http://www.carlosag.net/tools/>here</a></body>

Default Documents

IIS has a feature called Default Document that allows you to specify the content that should be processed when a user enters a URL that is mapped to a directory and not an actual file. In other words, if the user enters http://www.carlosag.net/tools/ then they will actually get the content as if they entered http://www.carlosag.net/tools/default.aspx. That is all great, the problem is that this feature only works one way by mapping a Directory to a File, however it does not map the File to the Document, this means that if some of your links or other users enter the full URL, then search engines will see two different URL’s. To solve that problem we can use a configuration very similar to the rule above, following is a rule that will redirect the default.aspx to the canonical URL (the folder).

        <rule name=”Default Document” stopProcessing=”true”>
<match url=”(.*)default.aspx” />
<
action type=”Redirect” url=”{R:1}” redirectType=”Permanent” />
</
rule>

This again, uses a Permanent redirect to extract everything before Default.aspx and redirect it to the “parent” URL path, so for example, if the user enters http://www.carlosag.net/Tools/WindowsLiveWriter/default.aspx it will be redirected to http://www.carlosag.net/Tools/WindowsLiveWriter/ as well as http://www.carlosag.net/Tools/default.aspx to http://www.carlosag.net/Tools/. You can place this rule at the root of your site and it will take care of all the default documents (if you have a default.aspx in every folder)

2) Friendly URL’s

Asking your user to remember that www.contoso.com/books.aspx?isbn=0735624410 is the URL for the IIS Resource Kit is not the nicest thing to do, first of all why do they care about this being an ASPX and the fact that it takes arguments and what not. It seems that providing them with a URL like www.contoso.com/books/IISResourceKit will truly resonate with them and be easier for them to remember and pass along. Most importantly it really doesn’t tie you to any Web technology.

With URL Rewrite you can easily build this kind of logic automatically without having to modify your code using Rewrite Maps:

<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name=”Rewrite for Books” stopProcessing=”true”>
<match url=”Books/(.+)” />
<
action type=”Rewrite” url=”books.aspx?isbn={Books:{R:1}}” />
</
rule>
</rules>
<rewriteMaps>
<rewriteMap name=”Books”>
<add key=”IISResourceKit” value=”0735624410″ />
<
add key=”ProfessionalIIS7″ value=”0470097825″ />
<
add key=”IIS7AdministratorsPocketConsultant” value=”0735623643″ />
<
add key=”IIS7ImplementationandAdministration” value=”0470178930″ />
</
rewriteMap>
</rewriteMaps>
</rewrite>
</system.webServer>
</configuration>

The configuration above includes a rule that uses a Rewrite Map to translate a URL like: http://www.contoso.com/books/IISResourceKit into http://www.contoso.com/books.aspx?isbn=0735624410 automatically. Using maps is a very convenient way to have a “table” of values that can be transformed into any other value to be used in the result URL. Of course there are better ways of doing this when using large catalogs or values that change frequently but is extremely useful when you have a consistent set of values or when you can’t make changes to an existing application. Note that since we use Rewrite the end users never see the “ugly-URL” unless they knew it already and typed it, and of course this means you can use the inverse approach to ensure the canonicalization is preserved:

    <rewrite>
<rules>
<rule name=”Redirect Books to Canonical URL” stopProcessing=”true”>
<match url=”books\.aspx” />
<
action type=”Redirect” url=”Books/{ISBN:{C:1}}” appendQueryString=”false” />
<
conditions>
<add input=”{QUERY_STRING}” pattern=”isbn=(.+)” />
</
conditions>
</rule>
</rules>
<rewriteMaps>
<rewriteMap name=”ISBN”>
<add key=”0735624410″ value=”IISResourceKit” />
<
add key=”0470097825″ value=”ProfessionalIIS7″ />
<
add key=”0735623643″ value=”IIS7AdministratorsPocketConsultant” />
<
add key=”0470178930″ value=”IIS7ImplementationandAdministration” />
</
rewriteMap>
</rewriteMaps>
</rewrite>

The rule above does the “inverse” by matching the URL books.aspx, extracting the ISBN query string value and doing a lookup in the ISBN table and redirecting the client to the canonical URL, so again if user enters http://www.contoso.com/books.aspx?isbn=0735624410 they will be redirected to http://www.contoso.com/books/IISResourceKit.

This Friendly URL to me is more of a user feature than a SEO feature, however I’ve read in every SEO guide to reduce the number of parameters in your Query String, however, I have not find yet any document that clearly states if there is truly a limit in the search engine bot’s that would truly impact the search relevance. I guess it makes sense that they wouldn’t keep track of thousands of links to a catalog.aspx that has zillions of permutations based on hundreds of values in the query string (category, department, price range, etc) even if all of them were linked, but again I don’t have any prove.

3) Site Reorganization

One complex tasks that Web Developers face sometimes is trying to reorganize their current Web Site structure, whether its moving a section to a different path, or something as simple as renaming a single file, you need to take into consideration things like, Is this move a temporary thing?, How do I ensure old clients get the new URL?, How do I prevent losing the search engine relevance?. URL Rewrite will help you perform these tasks.

Rename a file

If you rename a file you can very easily just write a Rewrite or Redirect Rule that ensures that your users continue getting the content. If your intent is to never go back to the old name you should use a Redirect Permanent so everyone starts getting the new content with its new “Canonical URL”, however, if this could be a temporary thing you should use a Redirect Temporary. Finally a Rewrite is useful if you still want both URL’s to continue to be valid (though this breaks the canonicality).

      <rule name=”Rename File.php to MyFile.aspx” stopProcessing=”true”>
<match url=”File\.php” />
<
action type=”Redirect” url=”MyFile.aspx” redirectType=”Permanent” />
</
rule>

Moving directories

Another common scenario is when you need to move an entire directory to another place of the Web Site. It could also be that based on some criteria (say Mobile browsers or other User Agent) get a different set of pages/images. Either way, URL rewrite helps with this. The following configuration will redirect every call to the /Images directory to the /NewImages directory.

      <rule name=”Move Images to NewImages” stopProcessing=”true”>
<match url=”^images/(.*)” />
<
action type=”Redirect” url=”NewImages/{R:1}” redirectType=”Permanent” />
</
rule>

A related scenario is if you wanted to show different smaller images whenever a user of Windows CE was accessing your site, you could have a “img” directory where all the small images are stored and use a rule like the following:

        <rule name=”Use Small Images for Windows CE” stopProcessing=”true”>
<match url=”^images/(.*)” />
<
action type=”Rewrite” url=”/img/{R:1}” />
<
conditions>
<add input=”{HTTP_USER_AGENT}” pattern=”Windows CE” ignoreCase=”false” />
</
conditions>
</rule>

Note, that in this case the use of Rewrite makes sense since we want the small images to look as the original images to the browser and it will save a “round-trip” to it.

Moving multiple files

Another common operation is when you randomly need to relocate pages for whatever reason (such as Marketing Campaigns, Branding, etc). In this case if you have several files that have been moved or renamed you can have a single rule that catches all of those and redirects them accordingly. Similarly, another sample could include an incremental migration from one technology to another where say you are moving from Classic ASP to ASP.NET and as you rewrite some of the old ASP pages into ASPX pages you want to start serving them without breaking any links or the search engine relevance.

    <rewrite>
<rules>
<rule name=”Redirect Old Files and Broken Links” stopProcessing=”true”>
<match url=”.*” />
<
conditions>
<add input=”{OldFiles:{REQUEST_URI}}” pattern=”(.+)” />
</
conditions>
<action type=”Redirect” url=”{C:0}” />
</
rule>
</rules>
<rewriteMaps>
<rewriteMap name=”OldFiles”>
<add key=”/tools/WebChart/sample.asp” value=”tools/WebChart/sample.aspx” />
<
add key=”/tools/default.asp” value=”tools/” />
<
add key=”/images/brokenlink.jpg” value=”/images/brokenlink.png” />
</
rewriteMap>
</rewriteMaps>
</rewrite>

Now, you can just keep adding to this table any broken link and specify its new address.

Others

Other potential use of URL Rewrite is when using RIA applications in the browser, whether using things like AJAX, Silverlight or Flash, that are not easy to parse and index by search engines, you could use URL Rewrite to rewrite the URL to static HTML versions of your content, however you should make sure that the content is consistent so you don’t misguide users and search engines. For example the following rule will rewrite all the files in the RIAFiles table to their static HTML counterpart but only if the User Agent is the MSNBot or the GoogleBot:

    <rewrite>
<rules>
<rule name=”Rewrite RIA Files” stopProcessing=”true”>
<match url=”.*” />
<
conditions>
<add input=”{HTTP_USER_AGENT}” pattern=”MSNBot|Googlebot” />
<
add input=”{RIAFiles:{REQUEST_URI}}” pattern=”(.+)” />
</
conditions>
<action type=”Rewrite” url=”{C:0}” />
</
rule>
</rules>
<rewriteMaps>
<rewriteMap name=”RIAFiles”>
<add key=”/samples/Silverlight.aspx” value=”/samples/Silverlight.htm” />
<
add key=”/samples/MyAjax.aspx” value=”/samples/MyAjax.htm” />
</
rewriteMap>
</rewriteMaps>
</rewrite>

Related to this is that you might want to prevent search engines from crawling certain files (or your entire site), for that, you can use the Robots.txt semantics and use a “disallow”, however, you can also use URL Rewrite to prevent this with more functionality such as blocking only a specific user agent:

    <rewrite>
<rules>
<rule name=”Prevent access to files” stopProcessing=”true”>
<match url=”.*” />
<
conditions>
<add input=”{HTTP_USER_AGENT}” pattern=”SomeRandomBot” />
<
add input=”{NonIndexedFiles:{REQUEST_URI}}” pattern=”(.+)” />
</
conditions>
<action type=”AbortRequest” />
</
rule>
</rules>
<rewriteMaps>
<rewriteMap name=”NonIndexedFiles”>
<add key=”/profile.aspx” value=”block” />
<
add key=”/personal.aspx” value=”block” />
</
rewriteMap>
</rewriteMaps>
</rewrite>

There are several other things you can do to ensure that your Web Site is friendly with Search Engines, however most of them require changes to your application, but certainly worth the effort, for example:

  • Ensure your HTML includes a <title> tag.
  • Ensure your HTML includes a <meta name=”description”.
  • Use the correct HTML semantics, use H1 once and only once, use the alt attribute in your <img>, use <noscript> etc.
  • Redirect using status code 301 and not 302.
  • Provide Site Map’s and/or Robots.txt.
  • Beware of POST backs and links that require script to run.

Resources

For this entry I read and used some of the resources at several Web Sites, including:


Topics: , , ,

0

Posted by Michael Alfaro on February 1, 2012

Oracle Client, IIS7 – The specified store provider cannot be found in the configuration, or is not valid.

Ran into this when moving a currently working site to a new directory and setting it up as another site.  All IIS and web.config settings matched, so couldn’t figure out why every time I tried to go to a page the needed an Oracle connection I kept getting “The specified store provider cannot be found in the configuration, or is not valid.”

Finally remembered that the App Pool itself has “Advanced Settings”, not just the basic ones which I had already checked.  The Oracle Instant Client we’re using is 32 bit, thus the 2nd setting in the App Pool >> Advanced Settings >> Enable 32-Big Applications had to be set to True instead of the default of False.

Check it out here:


Topics: , , , ,

0

Posted by Michael Alfaro on December 15, 2011

Execute SQL Queries directly in LINQ

Sometimes you have complex SQL that uses DB specific functions, and to put into LINQ is more work then it’s worth.  So our Developer Sergio found this article how do to directly execute SQL through LINQ: http://msdn.microsoft.com/en-us/library/bb399403.aspx

“LINQ to SQL translates the queries you write into parameterized SQL queries (in text form) and sends them to the SQL server for processing.

SQL cannot execute the variety of methods that might be locally available to your application. LINQ to SQL tries to convert these local methods to equivalent operations and functions that are available inside the SQL environment. Most methods and operators on .NET Framework built-in types have direct translations to SQL commands. Some can be produced from the functions that are available. Those that cannot be produced generate run-time exceptions. For more information, see SQL-CLR Type Mapping (LINQ to SQL).

In cases where a LINQ to SQL query is insufficient for a specialized task, you can use the ExecuteQuery method to execute a SQL query, and then convert the result of your query directly into objects.

In the following example, assume that the data for the Customer class is spread over two tables (customer1 and customer2). The query returns a sequence of Customer objects.

C#

Northwnd db = new Northwnd(@"c:\northwnd.mdf");
IEnumerable<Customer> results = db.ExecuteQuery<Customer>
(@"SELECT c1.custid as CustomerID, c2.custName as ContactName
    FROM customer1 as c1, customer2 as c2
    WHERE c1.custid = c2.custid"
);

As long as the column names in the tabular results match column properties of your entity class, LINQ to SQL creates your objects out of any SQL query.

The ExecuteQuery method also allows for parameters. Use code such as the following to execute a parameterized query.

C#

Northwnd db = new Northwnd(@"c:\northwnd.mdf");
IEnumerable<Customer> results = db.ExecuteQuery<Customer>
    ("SELECT contactname FROM customers WHERE city = {0}",
    "London");

The parameters are expressed in the query text by using the same curly notation used by Console.WriteLine() and String.Format(). In fact, String.Format() is actually called on the query string you provide, substituting the curly braced parameters with generated parameter names such as @p0, @p1 …, @p(n).”


Topics: , , , ,

2

Posted by Michael Alfaro on December 7, 2011

Disable password policy settings in BPOS and Office 365 with PowerShell-PasswordNeverExpires

We switched to Office 365 about 90 days ago, and it’s been working great.  Now we’re running into the 90 day default password policy from Microsoft which we want to avoid.  We found how to turn off the policy for all current members of our 365 subscription.  Here’s the original source: http://blog.atwork.at/post/2011/10/30/Passwordneverexpire-Kennwortrichtlinie-andern-in-BPOS-und-in-Office-365-mit-Hilfe-von-PowerShell.aspx

“Office 365 has a password policy, which is by default set to expire on a regular basis (90 days). There are some guidelines which help to make sure that the password is secure:

  • Use 8 to 16 characters
  • combination of upper- and lowercase letters
  • at leat one numer or one symbol (be aware that the symbol is available in every language on every keyboard)
  • Do not use spaces, tabs, line breaks, your user name

Each user is able to change his password at any time. If a user forgets his password it can be reset by an Office 365 administrator.

In some cases – for example for service accounts – it is useful to change the password expiration policy to never expire.

In this post I will show you how you can disable the password expiration for Office 365 and for BPOS as well.

Password Policy change to never expire in Office 365

In office 365 you need only two lines to disable the password policy. First open the Microsoft Online Services Modul for Windows Powershell. (Download: 32bit or 64bit).

Connect to Office 365

Connect-MsolService

In the dialog enter the credentials of an administrator:




To change a single user:

Set-MsolUser -UserPrincipalName <username> -PasswordNeverExpires $True

To change all users at once:

Get-MsolUser | Set-MsolUser -PasswordNeverExpires $True




That’s it. You can control the result with the following command:

Get-MsolUser | fl


Topics: , , ,

0

Posted by Michael Alfaro on November 8, 2011

Omnitouch, any surface becomes an input device

Found this on yahoo news. With the use of a Microsoft Kinect, some Grad students figured out how to project onto any surface and make that surface an input device, pretty impressive:


Topics: , , , , ,

2

Posted by Michael Alfaro on October 26, 2011

IIS 7 Web.config change for HTML5 and CSS3 mime types

Needed to add new mime types to an ASP.NET application that will be running on IIS7, and found this great article that sets you up for a bunch of file types that are common to HTML5 and CSS3.  Original Source: http://madskristensen.net/post/Prepare-webconfig-for-HTML5-and-CSS3.aspx

“When a request is made to the IIS for these unsupported file types, we are met with the following error message:

HTTP Error 404.3 – Not Found

The page you are requesting cannot be served because of the extension configuration. If the page is a script, add a handler. If the file should be downloaded, add a MIME map.

The problem is that the IIS doesn’t know how to serve these new files unless we tell it how. This can be easily done in the web.config’s <system.webServer> section by adding the following snippet:

<staticContent>
    <mimeMap fileExtension=".mp4" mimeType="video/mp4" />
    <mimeMap fileExtension=".m4v" mimeType="video/m4v" />
    <mimeMap fileExtension=".ogg" mimeType="video/ogg" />
    <mimeMap fileExtension=".ogv" mimeType="video/ogg" />
    <mimeMap fileExtension=".webm" mimeType="video/webm" />
    <mimeMap fileExtension=".oga" mimeType="audio/ogg" />
    <mimeMap fileExtension=".spx" mimeType="audio/ogg" />
    <mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
    <mimeMap fileExtension=".svgz" mimeType="image/svg+xml" />
    <remove fileExtension=".eot" />
    <mimeMap fileExtension=".eot" mimeType="application/vnd.ms-fontobject" />
    <mimeMap fileExtension=".otf" mimeType="font/otf" />
    <mimeMap fileExtension=".woff" mimeType="font/x-woff" />
</staticContent>

The above snippet includes support for most video, audio and font file types used by HTML5 and CSS3.”


Topics: , , ,

0

Posted by Michael Alfaro on October 11, 2011

Monitor open ports on Windows machines

Needed the other day for a website that making an LDAP connection out to another box and had to find out if it was at least attempting to go out.  The app is a bit old school, but it worked on Windows 64-bit OS server.  CurrPorts worked great, even allows filtering so I was able to look for only the LDAP port.

Can be downloaded here: http://www.nirsoft.net/utils/cports.html


Topics: , ,

0

Posted by Michael Alfaro on September 25, 2011

Change the number of days for Office 365 delete retention policy

Found the answer here: http://help.outlook.com/en-us/140/gg271153.aspx#defaulttags

Example   Here’s a command to increase the retention age limit for the Delete Items retention tag to 90 days:

Set-RetentionPolicyTag "Deleted Items" -AgeLimitForRetention 90

The article also shows how to set up and manage retention policies in exchange online


Topics: , , ,

0

Posted by Michael Alfaro on September 5, 2011

Office 365, change the default email address on a Shared Mailbox

Ran into this problem after I created a shared mailbox, without specifying which email address I wanted to be the primary one.  Original source here:  http://www.bpossibility.com/2011/08/10/office-365-shared-mailbox-how-to-change-the-default-email-address/

 

“Office 365 brings Shared Mailboxes that allow users interact with a common Inbox and Calendar.  The following site describes how these are made, licensing and other ins-and-outs such as setting Litigation Hold and delegating control to users:

http://help.outlook.com/en-us/140/ee441202.aspx

Although following these steps will probably create the wrong primary SMTP address.

Other situations, such as multiple domains in the one Office 365 tenant, will more than likely raise the need for several Shared Mailboxes in different domains.

When creating the Shared Mailbox specify the -PrimarySmtpAddress, below is an example:
New-Mailbox -Name “Shared Mailbox” -Alias sharedmbx -Shared -PrimarySmtpAddress SharedMbx@DOMAIN.COM


Topics: , , ,