Saturday, 20 February 2021

C#: Define what is Let clause?

 In a query expression, it is sometimes useful to store the result of a sub-expression in order to use it in subsequent clauses. You can do this with the let keyword, which creates a new range variable and initializes it with the result of the expression you supply.

 

 

var names = new string[] { "Dog", "Cat", "Giraffe", "Monkey", "Tortoise" };
var result =
    from animalName in names
    let nameLength = animalName.Length
    where nameLength > 3
    orderby nameLength
    select animalName; 

 Reference: Kill Your Tech Interview

SQL Server: What is the purpose of ROWLOCK on Delete and when should I use it?

 

Rowlock is a query hint that should be used with caution (as is all query hints).

Omitting it will likely still result in the exact same behaviour and providing it will not guarantee that it will only use a rowlock, it is only a hint afterall. If you do not have a very in depth knowledge of lock contention chances are that the optimizer will pick the best possible locking strategy, and these things are usually best left to the database engine to decide.

ROWLOCK means that SQL will lock only the affected row, and not the entire table or the page in the table where the data is stored when performing the delete. This will only affect other people reading from the table at the same time as your delete is running.

If a table lock is used it will cause all queries to the table to wait until your delete has completed, with a row lock only selects reading the specific rows will be made to wait.

Deleting top N where N is a number of rows will most likely lock the table in any case.

 

Reference: What is the purpose of ROWLOCK on Delete and when should I use it?

Thursday, 18 February 2021

Angular: ng.ps1 cannot be loaded because running scripts is disabled on this system on angular.

Solution: Run the following command from the same terminal or command prompt and re-run the ng command to check if it works on your machine:

Sol 1:  Set-ExecutionPolicy RemoteSigned -Scope CurrentUser

Sol 2: make sure that you are running the command in the application root folder..

 


 

 

Ref: ng : File \AppData\Roaming\npm\ng.ps1 cannot be loaded. The file npm\ng.ps1 is not digitally signed Angular Error when running commands

Ref: Angular CLI Error: The serve command requires to be run in an Angular project, but a project definition could not be found 

Saturday, 14 April 2018

HTML: rel= noopener noreferrer meaning

rel="noopener noreferrer" should be added to links containing target="_blank" as a precaution against reverse tabnabbing

noopener
“Instructs the browser to open the link without granting the new browsing context access to the document that opened it — by not setting the Window.opener property on the opened window (it returns null).”

noreferrer
“Prevents the browser, when navigating to another page, to send this page address, or any other value, as referrer via the Referer: HTTP header.”

References:
1. Why am I seeing rel=”noopener noreferrer” in my WordPress links?
2. Add rel="noopener noreferrer" to target="_blank"

jQuery Versions Vulnerable

jQuery VersionIs it Vulnerable?
jQuery 2.0.3Safe
jQuery 2.0.2Safe
jQuery 2.0.1Safe
jQuery 2.0.0Safe
jQuery 1.10.2Safe
jQuery 1.10.1Safe
jQuery 1.9.1Safe
jQuery 1.10.0Safe
jQuery 1.9.0Safe
jQuery 1.5.1Safe
jQuery 1.4.2Vulnerable
jQuery 1.6.1Vulnerable
jQuery 1.8.3Vulnerable
jQuery 1.6.2Vulnerable
jQuery 1.6.3Vulnerable
jQuery 1.7.2Vulnerable
jQuery 1.7.1Vulnerable
jQuery 1.6.0Vulnerable
jQuery 1.8.0Vulnerable
jQuery 1.5.0Vulnerable
jQuery 1.4.4Vulnerable
jQuery 1.6.4Vulnerable
jQuery 1.4.0Vulnerable
jQuery 1.8.1Vulnerable
jQuery 1.8.2Vulnerable
jQuery 1.5.2Vulnerable
jQuery 1.4.1Vulnerable
jQuery 1.7.0Vulnerable
jQuery 1.3.2Vulnerable
jQuery 1.4.3Vulnerable
jQuery 1.3.1Vulnerable
jQuery 1.3.0Vulnerable
jQuery 1.2.3Vulnerable
jQuery 1.2.6Vulnerable


References: 

Friday, 2 February 2018

How to monitor a windows service using vb script

1. The below-mentioned script is to monitor on a window service.

The service name is 'W3SVC' (World Wide Web Publishing Service), you can change the service name as per your requirement. If the script finds the service is stopped then it will start the stopped service.
The below code is a loop which runs the start service code every 15 seconds

**************************************************************************
do
   MyCode
   wscript.sleep 15000
loop

Sub MyCode
Set wmi = GetObject("winmgmts://./root/cimv2")
qry = "SELECT * FROM Win32_Service WHERE Name = 'W3SVC'"
For Each svc In wmi.ExecQuery(qry)
  If svc.State <> "Running" Then svc.StartService
Next
End Sub
****************************************************************************


2. The below-mentioned script is to kill all the vb scripts running in the background.
****************************************************************************
Option Explicit
Dim WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "taskkill /f /im Cscript.exe", , True
WshShell.Run "taskkill /f /im wscript.exe", , True
****************************************************************************

3. The below-mentioned script is to start multiple window services
****************************************************************************
do
   MyCode
   wscript.sleep 15000
loop

Sub MyCode
sComputer = "."
aTargetSvcs= Array ("W3SVC","aspnet_state","AdobeARMservice") 'array of window service
Set oWMIService =  GetObject("winmgmts://./root/cimv2")
Set cServices = oWMIService.ExecQuery("SELECT * FROM Win32_Service")
For Each oService In cServices
 For Each sTargetSvc In aTargetSvcs
  If LCase(oService.Name) = LCase(sTargetSvc) Then
  'MsgBox(oService.State) (commented code to check the status of the service in alert)
    If oService.State <>  "Running" Then 'check the status of the service
      oService.StartService() 
     End If
End if
Next
Next
End Sub
****************************************************************************

4.  vbscript terminate application / vbscript kill process
****************************************************************************



****************************************************************************

5. How to create a vb script
****************************************************************************
1. Open the notepad
2. Copy and paste the above script into the notepad
3. Save it as "test.vbs"
4. To test the same double-click on the "test.vbs"
****************************************************************************

References
1. How to stop a vb script running in windows
2. How do I stop / start service in VBScript?
3. re-run vbs script with time interval.
4. How to get a VBS script to start a service if it is stopped, with no window?
5. VBScript to start multiple services
6. VBA - Message Box

Friday, 5 January 2018

IIS redirect from HTTP to https

We recently faced an issue relating to URL Rewriting on our IIS 8 SharePoint 2013 server.
Firstly I would like to let you know the website current situation in which it was working.
Web Application was hosted on port 80 but after some configuration, it was moved to port 443 and port 80 was discontinued.
In addition, under SSL settings  require SSL was checked so the website can be only browsable when user upfront tries to browse via https://www.xyz.com by typing in the URL bar

When the user was trying to access http://xyz.com or https://xyz.com or http://www.xyz.com, it wasn't accessible at all and it was hampering the current SEO operations of our SharePoint 2013 web application in google.
Furthermore, We attempted all the permutation combinations of redirection to get it worked from HTTP to https when the user tries to access the website.

So, mentioned below are the permutation combinations as follows:
1. Defining New rules for redirection in URL rewrite tag of web.config file of SharePoint 2013 web application.
2. We reconfigured alternate access mapping.
3. Under SSL settings, we un-check require SSL option.
4. Under Http redirect, we tried all the options of redirect all the request to https://www.xyz.com but no relief.
5. A very childish option of letting the user visit the URL http://www.xyz.com and redirecting again to https://www.xyz.com via jquery/javascript

After spending the whole day behind the issue. We were left with no option to go with "No 5" for redirection from HTTP to https.
As leaving things behind we thought to give a try of re-installation of the setup.
1. press (windows + r) key  and it will open run
2. type appwiz.cpl and it will open control panel
3. under Programs and features, we repaired the "IIS URL rewrite option"
4. After repairing the module the IIS gets reset
5. We tried to browse the website using http://www.xyz.com and it redirected to https://www.xyz.com

After all the tantrums, the issue was fixed by repairing the IIS rewrite under control panel.

References:
Download URL Rewrite
Redirect from HTTP to HTTPS using the IIS URL Rewrite module
Redirect a user from HTTP to HTTPS using JavaScript