5 June 2012

To restart IIS


To restart IIS

  • Click Start, click Run type IISReset, and then click OK.

    A Command Prompt window opens displaying the status of the IISReset command. You should read the status at the command prompt to make sure that IIS stops and restarts.



1 June 2012

Application Path in Windows application in C#


Application Path in Windows application in C#

string exeFilePath = System.Reflection.Assembly.GetEntryAssembly().Location;
//Output:D:\Arun\SupportTools\PathForWindowsApplication\PathForWindowsApplication\bin\Debug\PathForWindowsApplication.exe

string exeDirectory = System.IO.Path.GetDirectoryName(exeFilePath);
//Output:D:\Arun\SupportTools\PathForWindowsApplication\PathForWindowsApplication\bin\Debug




Path Details in Asp.net - Absolute Path and Relative Path in asp.net


Path Details in Asp.net - Absolute Path and Relative Path in asp.net

        string applicationPath = string.Empty;
        string executionFilePath=string.Empty;
        string filePath = string.Empty;
        string path = string.Empty;

        string physicalApplicationPath = string.Empty;
        string physicalPath = string.Empty;
        string rawUrl = string.Empty;

        String rootPath = string.Empty;
        string mapPath = string.Empty;


        //Relative path
        //Only a Portion of full path

        //Absolute path
        //Contains Root directory and all Sub directory


       // Gets the ASP.NET application's virtual application root path on the server.

         applicationPath = Request.ApplicationPath + "/images/Nature.gif";

        //Output : /ApplicationPathInWeb/images/Nature.gif

        //Gets the virtual path of the current request.

         executionFilePath = Request.CurrentExecutionFilePath;

        //Output : /ApplicationPathInWeb/Default.aspx

         //Gets the virtual path of the current request.for the URL http://www.contoso.com/virdir/page.html/tail,      //the FilePath value is /virdir/page.html.

         filePath = Request.FilePath;

        //Output : /ApplicationPathInWeb/Default.aspx

         //Gets the virtual path of the current request.

         path = Request.Path;

        //Output : /ApplicationPathInWeb/Default.aspx

         physicalApplicationPath = Request.PhysicalApplicationPath;
        //Output:D:\Arun\SupportTools\ApplicationPathInWeb\

         physicalPath = Request.PhysicalPath;
        //Output:D:\Arun\SupportTools\ApplicationPathInWeb\Default.aspx

         rawUrl = Request.RawUrl;
        //Output:/ApplicationPathInWeb/Default.aspx

         rootPath = Server.MapPath("~");
        //Output:D:\Arun\SupportTools\ApplicationPathInWeb

         mapPath = Request.MapPath("~\\nature.jpg");
        //Output:D:\Arun\SupportTools\ApplicationPathInWeb\nature.jpg

Select statement and Case Statement in Sql Server


Select statement and Case Statement in Sql Server



SELECT   ProductNumber, Name, "Price Range" =
      CASE
         WHEN ListPrice =  0 THEN 'Mfg item - not for resale'
         WHEN ListPrice < 50 THEN 'Under $50'
         WHEN ListPrice >= 50 and ListPrice < 250 THEN 'Under $250'
         WHEN ListPrice >= 250 and ListPrice < 1000 THEN 'Under $1000'
         ELSE 'Over $1000'
      END
FROM Production.Product
ORDER BY ProductNumber ;


29 May 2012

Use Application Wrapper Class To Access Web.Config Values


Use Application Wrapper Class To Access Web.Config Values

Make sure you have a Reference to the System.Configuration.DLL

using System;using System.Collections.Generic;using System.Configuration;using System.Web;

public static class ApplicationWrapper{    #region public members
    
public static string DBConnection
    {
        
get { return ConfigurationManager.ConnectionStrings["DBConnection"].ConnectionString; }
    }
    
public static int MaxLoginAttempts
    {
        
get { return int.Parse(ConfigurationManager.AppSettings["MaxLoginAttempts"]); }
    }
    
public static string Company
    {
        
get { return ConfigurationManager.AppSettings["Company"]; }
    }
    #endregion}



26 May 2012

SQL Server Where 1=0

SQL Server Where 1=0

Used in both static and dynamic query.

WHERE 1 = 0 (or any always false condition) 

It is used to create a table of identical structure, sans data: In the below query empty table is created in the same structure.
SELECT * INTO dbo.NewTable FROM dbo.SomeTable WHERE 0 = 1;

SQL Server Where 1=1

SQL Server Where 1=1


where 1=1 condition are most probably used in dynamic query in Sql Server.

where 1=1 equal to no where condition [i.e] always return the true value.

While building dynamic query some times there is no need of where condition, To handle this kind of situation this condition SQL Server Where 1=1 is used.


SET @SelectStatement = 'SELECT SomeData FROM dbo.SomeTable WHERE 1  = 1';
IF @Column1 IS NOT NULL SET @SelectStatement = @SelectStatement + ' AND Column1 = @Column1';
IF @Column2 IS NOT NULL SET @SelectStatement = @SelectStatement + ' AND Column2 = @Column2';

Implementing OAuth validation in a Web API

 I mplementing OAuth validation in a Web API Implementing OAuth validation in a Web API using C# typically involves several key steps to sec...