Monday, July 28, 2014

Url Rewrite: Check Request URL Best Practice


Append or Remove the Trailing Slash Symbol



Enforce Lowercase URLs


Checking If a Request Is for a File or a Directory

Using String Functions with Rule Actions and Conditions


Add a note hereURL Rewrite offers three string functions that can be used with the rule actions and conditions:

·         Add a note hereToLower — Returns the string as lowercase.

·         Add a note hereUrlEncode — Returns the string as a URL-encoded format.

·         Add a note hereUrlDecode — Returns the string as a decoded string.

Url rewrite -Restrict Hot Linking Image of Website to be used by other website.

Hot-linking:
URL Rewrite can be also used to prevent/filter other sites from using your website images from their site . Hot-linking can increase traffic to your site , it also a kind of copyright issues.
 
Resolution: We can observe http_referer — the referring website. If it's not your own site, you can assume that it's a hot-link attempt. You must ensure that the domain name matches exactly, so it's wise to precede the hot-linking rule with the Canonical Domain Name rule.

The following example will replace the attempted image with your own image, called prohibited.png. This is  not fullproof solution as it rely on Http_referer as one can never use HTTP_Referer to get away with this.

Add a note here

   

      
Create URL Rewrite Rule
1. Click the URL Rewrite module.
2. Add Rules
3. Blank Rule
4. Name = Prevent image Hotlinking (Or whatever friendly name you would like)
5. Pattern = .*\.(gif|jpg|png)$
6. Add Condition
a. Condition Input = {HTTP_REFERER}
b. Input String = Does not Match the Pattern
c. Pattern = ^$
7. Add a second Condition
a. Condition Input = {HTTP_REFERER}
b. Input String = Does not Match the Pattern
c. Pattern = http://www.MyAuthenticWebsite.com/ .*   (Replace www.MyAuthenticWebsite.com with your domain)
8. Action Type = Rewrite
9. Rewrite URL = /images/prohibited.png    (Replace prohibited.png with whatever image you would like to show)
10. Click Apply
10. Click Back to Rules
      

         

          ^

http://MyWebsite.*" negate="true" />
      

       prohibited.png" />

   
 
By using this, as best practice,
  • we have shielded a security concerns,
  • try to safe guard copyright issue
  • To certain extent performance engineering by reducing unnecessary traffic from unknown sources.

Friday, July 25, 2014

ng-bind, ng-non-bindable, ng-bind-template and class="ng-bind:property"

Index.html

<html data-ng-app="app" id="ng-app" lang="sv">

<head>
 
 

<div data-ng-controller="oControllerA">

<h1>Controller A</h1>

<h2>{{dataObject}}</h2>

<h3>{{dataObject.color}}</h3>

<h3 ng-bind="dataObject.color"></h3>

<h3 ng-bind-template="{{dataObject.color}}"></h3>

<h3 ng-non-bindable>{{dataObject.color}}"</h3>

<h3 class="ng-bind:dataObject.color"></h3>

<input type=" text" data-ng-model="dataObject.color" />

</div>

Angular .Js
var app = angular.module('app', []);
app.factory('ShareService', function () {

return {

dataObject: { color: "Seal" }



}

});
 
app.controller('oControllerA', ['$scope', 'ShareService', function ($scope, ShareService) {



$scope.dataObject = ShareService.dataObject;

}

]);
 

Output

Controller A

{"color":"Seal"}

Seal

Seal

Seal-  ng-bind-template here it can date format.

{{dataObject.color}}" - Ng-non-bindable

Seal


 

Tuesday, July 22, 2014

Angularjs: Directive With $observe and Events

This example helps you understand the working of directive with respect to UI element. One can control the behavior of UI element using directive in AngularJs. There can be many other purpose for which directive can be useful. I could only see directive mostly use to manage UI behavior.

Few important things:

1. We can use thermometer inside div as attribute
2. We can use data-thermometer inside div as mentioned below.
3. We can use attr.observe or attr.$observe





 

Monday, July 21, 2014

AngularJS : Controller Factory Service Example

The sample below code demonstrate use of factory with controller and how we can share data among controllers.

Html Output

Controller A

{"color":"Seal"}

Seal


Controller B

{"color":"Seal"}

Seal


<html data-ng-app="app" id="ng-app" lang="sv">

<head>

<title>Customer App</title>
</head>

<body>
 

<div data-ng-controller="oControllerA">

<h1>Controller A</h1>

<h2>{{dataObject}}</h2>

<h3>{{dataObject.color}}</h3>

<input type="text" data-ng-model="dataObject.color" />

</div>

<div data-ng-controller="oControllerB">

<h1>Controller B</h1>

<h2>{{dataObject}}</h2>

<h3>{{dataObject.color}}</h3>

<input type="text" data-ng-model="dataObject.color" />

</div>
</body>

</html>

CustomerController.js


var app = angular.module('app', []);

app.factory('ShareService', function () {

return {

dataObject: { color: "Seal" }



}

});
 
app.controller('oControllerA', ['$scope', 'ShareService', function ($scope, ShareService) {



$scope.dataObject = ShareService.dataObject;

}

]);
 
app.controller('oControllerB', ['$scope', 'ShareService', function ($scope, ShareService) {



$scope.dataObject = ShareService.dataObject;

}

]);
 
 

Friday, July 18, 2014

Http.sys Cache · UriScavengerPeriod. Default value: 120 seconds.

· UriScavengerPeriod. Default value: 120 seconds.

Important Registry Setting for production IIS web server environment.
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Http\Parameters


Below description do not belong to me..

I referred below blog :
http://performance-expert.blogspot.se/2012/06/high-performance-websites-stanford.html

The http.sys cache is periodically scanned by a scavenger, and entries that are not accessed between scavenger scans are removed. Setting the scavenger period to a high value reduces the number of scavenger scans. However, the cache memory usage might increase because older, less frequently accessed entries can remain in the cache. Setting the period too low causes more frequent scavenger scans, and it can result in too many flushes and cache churn

IIS Performance Tuning : allowSubDirConfig="false"

As a best practice , never allow nested web.config for single website. Avoid using multiple web.config as applicationhost.config try to make traversal search to locate web.config. As a best practice there should be one web.config.

Changes in Applicationhost.config 
    
     
    
            
    

        
    
 
Remove unnecessary module such windows authentication , if web site is open to all web users.

TCP Stack Tuning- MaxUserPort Registry

Increase Concurrent Request - Ports per IP Address.

Environment IIS 8.0 + Windows 2012 R2
*       
Type Win + R Run Command
Type Regedit

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Tcpip\Parameters\MaxUserPort
If MaxUserPort not exists, create this to fine tune the TCP port.
Windows create 5000 port connections for 1 IP address. We can increase this size upto max value=65,534
This will ensure maximum concurrent connections requests are served by the web server. Also try to fine tune the website connection limit in website advanced settings  and queue length in application pool.
http://social.technet.microsoft.com/Forums/en-US/69449ce9-ea58-48ec-b675-c55480ba4bbb/windows-server-2012-and-tcpip-maxuserport?forum=winserverPN
 

Thursday, July 17, 2014

IIS 8: Production Web Server sysdm.cpl System Properties

  1. WIN+R, Run
  2. Type sysdm.cpl into the Run box, and hit Enter.
  3. Below Setting and configuration must be perform to boost your server performance.
  4. Background Service Option
  5. Adjust for best performance.
  6. You can also check Virtual memory- paging - Not covered in this blogpost.
  7.  


  8.  

IIS 8 : Configure OS Level Web Server Optimization

If the given web server is in production and we want to increase the throughput reduce resource utilization and memory consumption. We must then closely look into below service and disabled them if not require.

  1. Win+R Run command
  2. Type  Services.msc
SERVICE NAME
DESCRIPTION
Application Experience
This is application level cache such as office and other application.
Distributed Link Tracking Client
Sharing across network and system
IP Helper
Depend on whether we using IPv4 or IPv6
Network List Service
List network level connected resource
Print Spooler
Printer option
Remote Registry
Enable access of registry remotely
Secondary Logon
Enables additional logon credential for services. Depends.

By disabling above services will save memory and CPU processing cycle.


Reference Book:
Professional Microsoft IIS 8

 

Encryption and decryption in powershell


Encryption:

 

·         PS C:\> read-host -assecurestring | convertfrom-securestring | out-file C:\cred.txt

 

Decryption:

 

·         $PlainTextPassword= [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR( (ConvertTo-SecureString $credential.Password) ))