Home
Powershell Process memory checker
- Details
This is a simple script to check how much memory is using for a given process name
$oProcList=get-wmiobject win32_process | where{$_.name -eq "cgi.exe"}
$total=$NULL
foreach($item in $oProcList){
$mem=$item.workingsetsize
$total+=$mem
}
$rez=($total/1mb)
$rez
google search
- Details
var searchReturned = false; try { // #1 google.load('search', '1', {language : 'en'}); google.setOnLoadCallback(function() { var customSearchControl = new google.search.CustomSearchControl('XXXXXXXXXX'); customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET); customSearchControl.setNoResultsString("Your search didn't return any results."); customSearchControl.setSearchStartingCallback(this, function(control, searcher, query) { // #2 searcher.setQueryAddition("inurl:<<searchPath>>"); searcher.setRestriction(google.search.Search.RESTRICT_EXTENDED_ARGS,{ "filter" : "0" }); }); customSearchControl.setSearchCompleteCallback(this, function(control, searcher){ $("#search_preload, .gs-no-results-result").hide(); $("#search_postload").show(); // #3 if($('.gs-spelling').length) { $('.gs-spelling a').html($('.gs-spelling a').html().replace(/inurl:.+/g,"")); } // #4 try { numResults=searcher.cursor.estimatedResultCount; $("#searchResultNum").text(numResults); var cpi = searcher.cursor.currentPageIndex; if (cpi < searcher.cursor.pages.length - 1) { $('#cse .gsc-cursor').append('<div class="gsc-cursor-page">Next</div>').click(function() { searcher.gotoPage(cpi + 1); }); } if (cpi > 0) { $($('#cse .gsc-cursor').prepend('<div class="gsc-cursor-page">Previous</div>').children()[0]).click(function() { searcher.gotoPage(cpi - 1); }); } } catch(e){} window.scrollTo(0,0); searchReturned=true; }); var options = new google.search.DrawOptions(); options.setInput($('#search-box-input')); options.setDrawMode(google.search.SearchControl.DRAW_MODE_TABBED); customSearchControl.draw('cse', options); // #5 customSearchControl.execute('<<query>>'); }, true); } catch(err) {} // #6 setTimeout(function(){ if(!searchReturned && $('#cse').length == 0) $("#search_preload").html("<h2 style='color:red;'>There was an error performing your search, please try again later.</h2>"); }, 10000);
If you're using the Custom Search Element, find this line in your code:
customSearchControl.draw('cse', options);
Above that line, add this code:
customSearchControl.setSearchStartingCallback(this,
function(control, searcher, query) {
searcher.setQueryAddition('-inurl:https');
});
make sure you add this to the result section of your page not the form box.
List of Common TCP/IP port numbers
- Details
List of Common TCP/IP port numbers Port 21 International Standard FTP port This is the port used for all FTP based file transfers, such as with programs like FTP Voyager, WS_FTP, Cute FTP, FTP NOW, and many more. (FTP =File Transfer Protocol). Port 22 International Standard SSH Server Listening port port used by Secure Shell servers, SSH, to listen for incoming connections. Port 23 International Standard Telnet port The port used by all Telnet applications. Port 25 International Standard SMTP mail port Standard port used for SMTP mail delivery. This is the outgoing mail port used by email programs such as Outlook Express, Outlook, FoxMaiI, and hundreds more, and it is also the SMTP Outgoing port used by mail Servers such as Axigen Mail Server, CMaiIServer, Lotus Notes, MaiIEnabIe, Merak Mail Server, Microsoft Exchange, Novell Group\/\Ase, Qmail, PostCast Server, PostFix, SendMaiI, SurgeMaiI, TFS Secure Message Server, V\AnMaiI, or any other SMTP / ESMTP standards compliant e-mail MTA (Message Transfer Agent). Port 42 Microsoft WINS Replication port port used to replicate NETBIOS name tables from one Windows Server to another (see port 137 also) Port 43 International Standard WHOIS port port used for "WhoIs" requests (for the retrieval of domain name information) to whois servers. Port 53 International Standard DNS port for DNS reguests & replies This port is used by clients and Servers when exchanging Domain Name information and routing. (DNS =Domain Name Server). Port 67 International Standard DHCP port for DHCP reguests & replies This is the port used by the DHCP Server and clients when the clients checks with the DHCP Server for a new lease and the allocation of an IP address. (DHCP =Dynamic Host Configuration Protocol). Port 79 International Standard Finger command for SMTP Mailservers - ETRN Finger port port used by SMTP mail Servers to send ETRN Finger commands to message queues Servers so that those message queues servers know that the mail Servers are online and ready to accept queued up mail. In short : this is the port which your email Server will use to send an ETRN command to your web hosting company’s mail Servers so that they deliver to you any waiting incoming mail. Port 80 International Standard HTTP port - Internet traffic The port through which most Internet traffic goes through, through HTTP requests. This is the port which web browsers use to browse the web. Port 102 International Standard X.400 port X.400 is one of the earliest standards for communications between Message Handling Systems (MHS) in pre-Internet days. As a result X.400 includes provisions for the network communications to include information about the intended destination medium for the message (e.g: email, fax, telex, etc...). In the Windows world this port is used by default by Microsoft Exchange Server MTAs (Message Transfer Agent) to communicate with each other on internal networks with multiple Exchange servers. Port 110 International Standard POP3 port Standard port used for POP3 mail delivery and collection. This is the port normally called the Incoming Mail port in email programs such as Outlook Express, Microsoft Outlook, FoxMaiI, and others. Port 115 International Standard SFTP port (Secure File Transfer Protocol) Port used for FTP file transfers and modifications over a Secure Shell connection (SSH). This is sometimes mistakenly called "FTP over SSH" which it is not- it is actually a completely new file transfer protocol which includes additional features such as error detection, resumption of interrupted transfers, remote file removal, and enumeration (listing) of remote folders and files. Additionally, as the protocol operates within the SSH protocol which secures the connection through authentication and encryption, this protocol has the additional advantage ofoperating within a secure environment, something which basic FTP lacks totally (passwords and files are sent as clear text which can easily be intercepted and deciphered by snooping programs). Port 119 International Standard Newsgroups port Port used for newsgroups access. Port 123 International Standard Network Time Protocol port (NTP) Port used for checking and synchronising time with another computer (Time Server). For example, this is the port which Windows XP and Windows Vista use when you configure the clock to automatically synchronize itself with a time server on the Internet. Ditto when you configure a Windows Server to synchronize its time over the Internet. Port 135 Microsoft RPC Locator Service port The RPC locator Service (&mote Procedure Call) maintains a list of networked services that support RPC and DCOM standards. This list holds information regarding which ports and IP addresses the services are currently running on or listening on. Thanks to this list, other computers can query this service to find the details needed to connect to a desired RPC service. Port 137 Microsoft NetBIOS Name service port I WINS Port used by the NetBIOS protocol to find other computers on a workgroup network. On a Peer to Peer network this will be done via broadcast. If a Windows 2000 server or newer is in place, the discovery of other computers can be done with a centralised database called a WINS server (Windows Internet Naming §ervice) thereby reducing latency and bandwidth usage on the network. This is analogous to DNS for Internet domain names and Microsoft 2000 /2003 Domains. Port 143 International Standard Internet Message Access Protocol 4 jIMAP4 port) This port is used by IMAP4 servers. IMAP is a method of accessing emails stored remotely on a mail Server (a mailbox). This could be a mailbox at an ISP or a corporate mailserver IMAP4 is "the other" message access protocol - the first one, and most known, being POP3. IMAP works differently from POP3 : the connection to the remote mailbox is constant compared to the Connect-GetMessages- CIoseConnection method of POP3. IMAP allows more than one email client to be connected to the same mailbox at the same time - as a direct result it is the protocol of choice for hand-held devices like BIackBerrys as you can have your laptop, desktop PC, and BlackBerry all connected to your mailbox at the same time, something which is not possible with POP3 which requires exclusive access. Another major plus point of IMAP is the ability to retrieve pans of the email, such as the subject only, the message body only, or the attachments only - this is another reason for it being the protocol of choice for devices like BIackBerrys where the user can have the device configured to download and show only the message subjects and when the user decides to open the email in full, then at that point the device requests, specifically, the only the body of the message. Last but not least, the IMAP protocol includes the provision of message status flags which let the remote client know whether a message has been read, deleted, replied to, or fonivarded - again, this is crucial to BlackBerry- type devices as that is how the IMAP Server can synchronize messages between the device, the server, and any other device simultaneously accessing the same mailbox. Port 161 International Standard Simple Network Management Protocol (SNMP port) UDP port used to manage, configure, and gather information about network devices (e.g. Firewalls, Routers) in a unified and uniform manner across a varied range of manufacturers. Most Server operating systems, whether Windows or not, provide support for this protocol. Note : Home and Small office devices tend to use UPNP forthis purpose. Port 179 International Standard Border Gateway Protocol port The Bordergatewayjrotocol (BGP) is a routing protocol used to exchange routing information between routers in autonomous networks. Port 379 Microsoft Site Replication Serivces (SRS port) TCP port used by Microsoft Site Replication Services. This services enables LDAP enabled Servers to replicate between each other information stored on Microsoft Active Directory domain Controllers and Exchange Servers. Port 389 International Standard Light Weight Directory Access Protocol port (LDAP port) TCP port used to find and manage network resources on an a hierarchical network systems such as Novell Network Directory Trees (NDS), and Microsoft Active Directory Sen/ice Domains. Port 443 International Standard Secure HTTP traffic port (SSL port) This is the default port used for SSL encrypted communications (SSL = Secure Socket Layer), such as, for example, when you login to a secure site to purchase something. From a System Administrator’s viewpoint, this is the port that is used for incoming and outgoing SSL connections. Port 445 International Standard Microsoft Active Directory and SMB Protocol port This port is used by Microsoft Active Directory services and Microsoft SMB (Server Message Block) protocols. SMB is also known as "Microsoft Vwndows Network" and is the main protocol used by Microsoft Server Operating Systems for client/Server access, and file and printer sharing. Port 465 Google Google Mail Outgoing Mail Server Google uses this non-standard port for its Outgoing Mail Server for Google Mail. Use this port, smtp.gmaiI.com, and SSL connection (SMTP Server Authentication) when configuring your email client for Google Mail (GMAIL). Port 636 International Standard LDAP over SSL TCP port used for Lightweight Directory Access Protocol over Secure Socket Layer connections. This a standard added to LDAP to prevent the interception of information and credentials using the LDAP protocol. This standard is used by Microsoft Exchange Server and many other LDAP enabled Server applications. SEE LDAP PORT: 389 Port 993 International Standard Secure Internet Message Access Protocol port (Secure IMAP port) TCP Poit used for SSL Secured IMAP 4 access. See IMAP4 Poit: 143. Port 995 Google Google Mail Incoming POP3 Mail Server (GMAIL port) Google uses this non-standard port for its POP3 Incoming Mail Server for Google Mail (GMAIL). Use this port, pop.gmaiI.com, and SSL connection when configuring your email client. Port 1026 Novell Calendar Access Protocol port (CAP) Port used by Novell GroupWise for its Calendar Access Protocol. port 1026 is used by the Windows Task Scheduler or other Windows services. Port 1080 De-Facto Standard SOCKS I Online Chatting I Hotmail This port is used mainly by applications such as AOL Instant Messenger for online chatting. It is also used by Hotmail. Port 1090 De-Facto Standard Real Audio port port used by Real Audio video and audio streaming applications. Port 1433 Microsoft SQL Server Port & SQL Server Replication Port Used by Microsoft SQL server 6 and above for SQL replication between SQL servers. Port 1434 Microsoft SQL Server Monitoring Port Used by Microsoft SQL server to monitor SQL server performance. Port 1521 Oracle Default Oracle port Default port for connection to an Oracle database server. Port 1677 Novell Novell GroupWise Standard port used by Novell GroupV\Ase for TCP/IP communications between clients and agents and the GroupV\Ase Post Office Agent (POA). Port 1701 International Standard Layer Two Tunnelling Protocol port (L2TP port) A tunnelling and encryption standard used to connect two Private Business networks together over an Internet connection to create a Virtual Private Network (VPN). This protocol is seen as the replacement to PPTP (port 1723 listed below). Port 1720 De-Facto Standard H.323 port Port used for video conferencing equipment which usesthe H.323 protocol. Port 1723 International Standard Point to Point Tunnelling Protocol port (PPTP port) A tunnelling and encryption standard used to connect two Private Business networks together over an Internet connection (creating one Virtual Private Network). This is the default protocol for establishing a VPN on Windows 2000 Server. Port 1900 Microsoft Media Center Extender - Xbox 360port UDP inbound. Port used by Microsoft’s Xbox 360 when linking to Media Center. Port 2409 SPAMFighter SPAMFighter Content Classificationport UDP inbound and Outbound. Port used by the SPAMFighter software to communicate with its servers in order to determine which emails are spam or not. Port 3101 Research in Motion Blackbergy Enterprise Server (BES) Synchronization Port (BES port) If you have an outbound firewall, then you will need to open this port (TCP) to enable the Blackberry Enterprise Server to synchronize with the Blackberry devices. Additionally, depending on the configuration of your particular site, you may also need to port forward port 3101 from your router to the Blackberry Enterprise Server. Port 3306 MySQL AB Default MySQL Port Default port for connection to a MySQL database server. Port 3389 Microsoft Remote Desktop Port & Terminal Services Port TCP Inbound & Outbound. Default port used by Windows XP Remote Desktop Connection and Microsoft Terminal Server for Remote Desktop Connections and/or Terminal Services sessions. For added security it is recommended to change the Remote Desktop port from its default to a value of your choice - this can be changed in the Registry at HKLM\System\CurrentControlSet\Control\Ter minal Server\WinStations\RDP- Tcp\PortNumber (the "RDP-Tcp" part may have a different name ifyou renamed your Terminal Server \ Remote Desktop connection). Port 3390 Microsoft Media Center Extender - Xbox 360 port TCP Inbound. port used by Microsoft’s Xbox 350 when linking to Media Center. Port 3535 GoDaddy GoDaddy Secure SMTP Relay port port used by GoDaddy customers for email sending using SMTP relay with authentication over any ISP connection via GoDaddy’s Outgoing Mail Server, smtpout.secureserver.net. This enables GoDaddy customers to email from anywhere without having to constantly change their email settings to reflect the SMTP Server corresportding to the Internet connection they are using at the time - instead they can email through GoDaddy’s SMTP Relay regardless of where they are. Port 4321 De Facto Standard RWHOIS port port used for “RWhoIs" requests. Port 4664 Google Google Desktop Search port Port 5190 America On Line AOL Instant Messenger port port used by AIM, the_iOL Instant Messenger software. Port 5500 DuaIDesk DualDesk port Default port used by the DuaIDesk remote control software. Port 5631 PCAnywhere PCAnywhere 5631 TCP incoming port port on which a Symantec PC Anywhere host accepts incoming PC Anywhere connections and then continues to communicate with the remote PC. If you have a PC Anywhere host behind a firewall or firewalled router, then you need to allow (and possibly port fonxvard) incoming TCP connections on this port. Port 5632 PCAnywhere PCAnywhere 5632 UDP incoming port Port used by Symantec’s PC Anywhere for the streaming of screen updates during a PC Anywhere session. If you have a PC Anywhere host behind a firewall or firewalled router, then you need to allow (and possibly port fonrvard) incoming UDP connections on this port. Port 5900 ReaIVNC Ltd ReaIVNC Default Remote Control Port (De-facto VNC default This is the default ReaIVNC port for port port) forwarding to the ReaIVNC host. You should always change this port from its default as it is a well-known port for all VNC remote control programs and it will therefore be one of the first targets of hackers Port 7070 Real Networks Real Streaming Audio port Port used by Real Networks’ audio streaming servers. Port 7100 Novell Novell GroupWise Standard port used by Novell GroupV\Ase for TCP/IP communications between the Message Transfer Agent (MTA) and other agents. Port 8000 Mirra Inc Mirra Personal Server Communications port Port used by both the Mirra Client running on the PC, and the Mirra Personal Server, to communicate with each other. This is a TCP port. Port 8080 International Standard HTTP Internet traffic port The other port through which HTTP Internet traffic also goes through. Port 8799 Vodafone UK GPRS Internet Access Proxy port Port used for GPRS Internet Browsing on the Vodafone UK mobile phone network. If you are on Vodafone you typically need to configure your phone to access the Internet via a proxy on port 8799. The proxy address is : 212.183.137.12:8799. Port 8880 De Facto Standard CDDB port Port used by CD mastering software to communicate with an Internet based CDDB Server for requests about artist and track names. Port 9100 Google Google Web Accelerator port Port used by Google Web Acceleration technology. Google Web Accelerator supports natively only Internet Explorer and FireFox at the time of writing, 2-Sep-2006. Other browsers need to have their HTTP Proxy configured to 127.0.0.1 :9100. Port 39720 Lime Wire LLC LimeWire communications port This is the default port which the LimeWire peer-to-peer file-sharing program uses (can be changed by the end-user).
IIS rewrite rules
- Details
This post describes some of the tips and tricks that one may find useful when solving URL-based problems for their web server or web site. Each tip/trick has a description of a problem and then an example of how it can be solved with IIS 7 URL Rewrite Module.
1. Add or Remove Trailing Slash
Many web applications use “virtual URLs” - that is the URLs that do not directly map to the file and directory layout on web server’s file system. An example of such application may be an ASP.NET MVC application with URL format similar to this:http://stackoverflow.com/questions/60857/modrewrite-equivalent-for-iis-7-0 ) or a PHP application with URL format that looks like this:http://ruslany.net/2008/11/url-rewrite-module-release-to-web/) If you try to request these URLs with or without trailing slash you will still get the same page. That is OK for human visitors, but may be a problem for search engine crawlers as well as for web analytics services. Different URLs for the same page may cause crawlers to treat the same page as different pages, thus affecting the page ranking. They will also cause Web Analytics statistics for this page to be split up. This problem is very easy to fix with a rewrite rule. Having or not having a trailing slash in the URL is a matter of taste, but once you’ve made a choice you can enforce the canonical URL format by using one of these rewrite rules:
To always remove trailing slash from the URL:
<rule name="Remove trailing slash" stopProcessing="true"> <match url="(.*)/$" /> <conditions> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> </conditions> <action type="Redirect" redirectType="Permanent" url="{R:1}" /> </rule>
To always add trailing slash to the URL:
<rule name="Add trailing slash" stopProcessing="true"> <match url="(.*[^/])$" /> <conditions> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> </conditions> <action type="Redirect" redirectType="Permanent" url="{R:1}/" /> </rule>
2. Enforce Lower Case URLs
A problem similar to the trailing slash problem may happen when somebody links to your web page by using different casing, e.g.http://ruslany.net/2008/07/IISNET-Uses-Url-Rewrite-Module/ vs. http://ruslany.net/2008/07/iisnet-uses-url-rewrite-module/. In this case again the search crawlers will treat the same page as two different pages and two different statistics sets will show up in Web Analytics reports.
What you want to do is to ensure that if somebody comes to your web site by using a non-canonical link, then you redirect them to the canonical URL that uses only lowercase characters:
<rule name="Convert to lower case" stopProcessing="true"> <match url="[A-Z]" ignoreCase="false" /> <action type="Redirect" url="{ToLower:{R:0}}" redirectType="Permanent" /> </rule>
3. Canonical Hostnames
Very often you may have one IIS web site that uses several different host names. The most common example is when a site can be accessed via http://www.yoursitename.com and via http://yoursitename.com. Or, perhaps, you have recently changed you domain name from oldsitename.com to newsitename.com and you want your visitors to use new domain name when bookmarking links to your site. A very simple redirect rule will take care of that:
<rule name="Canonical Host Name" stopProcessing="true"> <match url="(.*)" /> <conditions> <add input="{HTTP_HOST}" negate="true" pattern="^ruslany\.net$" /> </conditions> <action type="Redirect" url="http://ruslany.net/{R:1}" redirectType="Permanent" /> </rule>
To see an example of how that works try browsing to http://www.ruslany.net/2008/10/aspnet-postbacks-and-url-rewriting/. You will see in the browser’s address bar that “www” is removed from the domain name.
4. Redirect to HTTPS
When a site that requires SSL is accessed via non-secure HTTP connection, IIS responds with HTTP 403 (Unauthorized) status code. This may be fine if you always expect that your site visitors will be typing “https://…” in the browser’s address bar. But if you want your site to be easily discoverable and more user friendly, you probably would not want to return 403 response to visitors who came over unsecure HTTP connection. Instead you would want to redirect them to the secure equivalent of the URL they have requested. A typical example is this URL: http://www.paypal.com. If you follow it you will see that browser gets redirected to https://www.paypal.com.
With URL Rewrite Module you can perform this kind of redirection by using the following rule:
<rule name="Redirect to HTTPS" stopProcessing="true"> <match url="(.*)" /> <conditions> <add input="{HTTPS}" pattern="^OFF$" /> </conditions> <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="SeeOther" /> </rule>
Note that for this rule to work within the same web site you will need to disable “Require SSL” checkbox for the web site. If you do not want to do that, then you can create two web sites in IIS – one with http binding and another with https binding – and then add this rule to the web.config file of the site with http binding.
5. Return HTTP 503 Status Code in Response
HTTP status code 503 means that the server is currently unable to handle the request due to maintenance. This status code implies that the outage is temporary, so when search engine crawler gets HTTP 503 response from your site, it will know not to index this response, but instead to come back later.
When you stop the IIS application pool for your web site, IIS will return HTTP 503 for all requests to that site. But what if you are doing maintenance to a certain location of the web site and you do not want to shut down the entire site because of that? With URL Rewrite Module you can return 503 response only when HTTP requests are made to a specific URL path:
<rule name="Return 503" stopProcessing="true"> <match url="^products/sale/.*" /> <action type="CustomResponse" statusCode="503" subStatusCode="0" statusReason="Site is unavailable" statusDescription="Site is down for maintenance" /> </rule>
6. Prevent Image Hotlinking
Image Hotlinking is the use of an image from one site into a web page belonging to a second site. Unauthorized image hotlinking from your site increases bandwidth use, even though the site is not being viewed as intended. There are other concerns with image hotlinking, for example copyrights or usage of images in an inappropriate context.
With URL Rewrite Module, it is very easy to prevent image hotlinking. For example the following rewrite rule prevents hotlinking to all images on a web site http://ruslany.net:
<rule name="Prevent image hotlinking"> <match url=".*\.(gif|jpg|png)$"/> <conditions> <add input="{HTTP_REFERER}" pattern="^$" negate="true" /> <add input="{HTTP_REFERER}" pattern="^http://ruslany\.net/.*$" negate="true" /> </conditions> <action type="Rewrite" url="/images/say_no_to_hotlinking.jpg" /> </rule>
This rule will rewrite a request for any image file to /images/say_no_to_hotlinking.jpg only if the HTTP Referer header on the request is not empty and is not equal to the site’s domain.
7. Reverse Proxy To Another Site/Server
By using URL Rewrite Module together with Application Request Routing module you can have IIS 7 act as a reverse proxy. For example, you have an intranet web server and you want to expose its content over internet. To enable that you will need to perform the following configuration steps on the server that will act as a proxy:
Step1: Check the “Enable proxy” checkbox located in Application Request Routing feature view is IIS Manager.
Step2: Add the following rule to the web site that will be used to proxy HTTP requests:
<rule name="Proxy"> <match url="(.*)" /> <action type="Rewrite" url="http://internalserver/{R:1}" /> </rule>
Note the http:// prefix in the rewrite rule action. That is what indicates that this request must be proxy’ed, instead of being rewritten. When rule has “Rewrite” action with the URL that contains the protocol prefix, then URL Rewrite Module will not perform its standard URL rewriting logic. Instead it will pass the request to Application Request Routing module, which will proxy that request to the URL specified in the rule.
8. Preserve Protocol Prefix in Reverse Proxy
The rule in previous tip always uses non-secure connection to the internal content server. Even if the request came to the proxy server over HTTPS, the proxy server will pass that request to the content server over HTTP. In many cases this may be exactly what you want to do. But sometimes it may be necessary to preserve the secure connection all the way to the content server. In other words, if client connects to the server over HTTPS, then the proxy should use “https://” prefix when making requests to content server. Similarly, if client connected over HTTP, then proxy should use “http://” connection to content server.
This logic can be easily expressed by this rewrite rule:
<rule name="Proxy"> <match url="(.*)" /> <conditions> <add input="{CACHE_URL}" pattern="^(https?)://" /> </conditions> <action type="Rewrite" url="{C:1}://internalserver/{R:1}" /> </rule>
9. Rewrite/Redirect Based on Query String Parameters
When rewriting/redirection decisions are being made by using values extracted from the query string, very often one cannot rely on having the query string parameters always listed in exact same order. So the rewrite rule must be written in such a way so that it can extract the query string parameters independently of their relative order in the query string.
The following rule shows an example of how two different query string parameters are extracted from the query string and then used in the rewritten URL:
<rule name="Query String Rewrite"> <match url="page\.asp$" /> <conditions> <add input="{QUERY_STRING}" pattern="p1=(\d+)" /> <add input="##{C:1}##_{QUERY_STRING}" pattern="##([^#]+)##_.*p2=(\d+)" /> </conditions> <action type="rewrite" url="newpage.aspx?param1={C:1}&amp;param2={C:2}" appendQueryString="false"/> </rule>
With this rule, when request is made to page.asp?p2=321&p1=123, it will be rewritten to newpage.aspx?param1=123¶m2=321. Parameters p1 and p2 can be in any order in the original query string.
10. Avoid Rewriting of Requests for ASP.NET Web Resources
ASP.NET-based web applications very often make requests to WebResources.axd file to retrieve assembly resources and serve them to the Web browser. There is no such file exists on the server because ASP.NET generates the content dynamically when WebResources.axd is requested. So if you have a URL rewrite rule that does rewriting or redirection only if requested URL corresponds to a file or a folder on a web server’s file system, that rule may accidentally rewrite requests made to WebResources.axd and thus break your application.
This problem can be easily prevented if you add one extra condition to the rewrite rule:
<rule name="RewriteUserFriendlyURL1" stopProcessing="true"> <match url="^([^/]+)/?$" /> <conditions> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> <!-- The following condition prevents rule from rewriting requests to .axd files --> <add input="{URL}" negate="true" pattern="\.axd$" /> </conditions> <action type="Rewrite" url="article.aspx?p={R:1}" /> </rule>
Page 29 of 40