Skip to main content

Posts

Showing posts from 2016

Secure Webservice - Restrict remote machine access

A lways we are looking to secure our application and services, in this part am sharing few simple way to secure web service. Suppose you want to invoke web service in local machine and hide the invoke section in remote machine that case you could do enable the following properties in web.config file. <webServices>     <protocols>         <add name = "HttpGet" />         <add name = "HttpPost" />     </protocols> </webServices> Adding HttpGet and HttpPost in web.config to make your web service in invoke only in local machine.  Suppose want to show custom splash page or helper page, whenever accessing the web service landing page (.asmx). The following code helps to accomplish <system.web>     <webServices>              <wsdlHelpGenerator href="spl...

Compress folder in C#

In .NET earlier version, we used to depends on third party dll to generate the compressed files in .zip format. Suppose we have to compress multiple folders, then have to compress each and every folders and files. In .NET framework 4.5 introduced ZipFile class. It helps to compress the folders by one line. ZipFile.CreateFromDirectory(startPath, zipPath); StartPath - Source directory ZipPath - Compressed file. Alternatively you could extract the compressed files by         ZipFile.ExtractToDirectory(zipPath, extractPath); more details, click here

ATLAS Toolkit throwing Unknown Error

Recently deploying old ASP.NET application into Windows server 2012 we faced Unknown error popup box error. In application used ATLAS toolkit to perform async operation. After deploying the application, We are getting unknown error (popup box) whenever visiting the ATLAS controls page. To resolve this error added the following meta tag in header section of each web page. Otherwise we could add into master page level instead of page level <meta http-equiv="X-UA-Compatible" content="IE=7" /> This code resolved the error in local environment, but still it throws error after deploying the application in server. To resolve the error in server, go to IIS, change application pool pipeline from Integrated to Classic mode. That's it.

Automatically taking VSS backup using batch file

To take VSS backup automatically using batch file. 1. Creating folder name with Current date 2. Taking VSS backup using ssarc command @ECHO OFF @TITLE Backing up source safe databases FOR /F "tokens=2-4 delims=/" %%i IN (’date /t') DO SET DATE=%%i_%%j_%%k mkdir  D:\VSS\Backup\%DATE% "D:\Program Files (x86)/Microsoft Visual SourceSafe\ssarc" -D- -I- D:\VSS\Backup\%DATE%\application.ssa $/SourceSafe/application

Set Application pool using batch file

To set application pool to web application through batch file @c: @cd c:\windows\system32\inetsrv @appcmd set app /app.name:"Default Web Site/ TestApp " /applicationPool:" Test Pool " TestApp - denotes web application name  Test Pool - denotes application pool

Delete 15 days old files using batch file

To delete 15 days old file using batch file forfiles -p "C:\Testing\Backup"-s -m ”.” /D -15 /C "cmd /c del @path" Suppose want to delete only txt file, then forfiles -p "C:\Testing\Backup"-s -m ”.txt” /D -15 /C "cmd /c del @path" Suppose want to delete 30 days old file then -30 instead of -15

Restrict user to access web service through browser

There is two way to restrict the user to access the web service from browser. Method : 1 <system.web>     <webServices>              <wsdlHelpGenerator href="CustomPage.aspx"></wsdlHelpGenerator> /     </webServices> </system.web>  We have to create CustomPage.aspx page that will redirect into when try to access service.asmx file. It is restrict the user to invoke the web method via browser. Suppose if  creating a new client application to consume the service, you could access the wsdl like Service.asmx?wsdl Method: 2 <system.web> <webServices>     <protocols>               <remove name="Documentation"/>     </protocols> </webServices> </system.web> Removing the documentation protocol and it won't allow us to access the WSDL like Service.asmx?wsdl

Request.ServerVariables["LOGON_USER"] returning empty ??

In Intranet application, we used to perform Windows Authentication to validate user. In ASP.NET, Request.ServerVariables["LOGON_USER"] is returning logged user name with domain value. but sometime when we are trying to access this server variable in web application it may return empty value. To resolve the issue, go to Web Site  / Web application project properties set Anonymous Authentication as Disabled and set Windows Authentication as Enabled. that's it. It will resolve the issue. Now can access all the server variables in web application

DB2 Performance Improvement Tips

1. Try to use column names instead of * in SELECT statement 2. Try to avoid IN clause 3. Try to avoid Casting, Data type conversion in WHERE clause 4. whenever joining with table, try to order the columns ( in ON Clause ) in same order of Indexed columns 5. When handling huge volume of table, approach Temporary table ( Session table) 6. Instead of using Sub query, try to use common table expression ( CTE ) 7. In WHERE clause, try to order the columns in same order of Indexed columns 8. Try to avoid CURSOR, In case if it is require go with read only CURSOR

DB2 - How to avoid IN clause

As know IN clause is one of the performance decrease operator when operating huge volume of data. Let see how to avoid IN clause and what could be alternative way to accomplish same functionality. This query contains IN clause and taking too much time SELECT column_list FROM TABLE1 WHERE Column_name in (SELECT column_name FROM TABLE2 ) To improve the performance of above query, could move the sub query statement into CTE ( Common Table Expression) and join with main query. WITH CTE AS (SELECT column_name FROM TABLE2 ) SELECT column_list FROM TABLE1 INNER JOIN CTE ON TABLE1.column_name = CTE.column_name That's it, The second query results tremendous improvement, when handling huge volume of data. Any other questions to improve the DB2 performances, please feel free to write up

Copy files and folders recursive in C#

This code written to copy files and folders recursively from one drive to another drive using C#, It could be physical storage, logical storage  or network location.  private static void Copy(string sourcePath, string targetPath)         {             foreach (string f in Directory.GetFiles(sourcePath))                 File.Copy(f, targetPath + "\\" + Path.GetFileName(f), true);             foreach (string d in Directory.GetDirectories(sourcePath))             {                 var dirName = Path.GetFileName(d);                 Directory.CreateDirectory(targetPath + "\\" + dirName);                 Copy(sourcePath + "\\" + dirName, targetPath + "\\" + dirName);           ...

Failed to retrieve COM component error

 To resolve the error, have to register the dll in Global Assembly Cache (GAC) using regsvr command. Execute the below command in command prompt REGSVR32 ABC.DLL After registration completed, we have to change project properties. Go to  Visual Studio - > Select project properties -> Build tab - > Change Platform Target to X86. It would be resolve the issue.