Monday, 23 April 2012

Error message when you visit a Web site that is hosted on IIS 7.5: "HTTP Error 404.17 - Not Found"

This article might help, but we need to look for three things particularly

configure the following settings to match the handler requirements:
  • .NET Framework Version
  • Enable 32-Bit Applications
  • Managed Pipeline Mode

HTTP 500.0 - Internal Server Error in Windows 2008 R2 Server

After deploying a 32-Bit WCF service in IIS 7.5(Windows 2008 R2 server), browsing the service failed with
HTTP 500.0 - Internal Server Error, and from the error message i figured out something wrong with PageHandlerFactory. For 32-Bit web apps, it is mandatory to set 'Enable 32-Bit Applications' to 'True'. We can either set it @ 'Application Pool Defaults' or the specific Application Pool in question.

Sample powershell scripts

ProjectDir - Project Folder
OutDir - either bin\debug or bin\release or whatever set as output directory

1. To Copy files from 'some folder' into output directory  - below copies everything from 'libs' folder which is at same level as that of our Project directory into Project directory's output.

    copy /Y $(ProjectDir)\..\libs\* $(ProjectDir)\$(OutDir)\

to be contd....

Friday, 13 April 2012

BadImageFormatException in Windows 2008 R2 Server

I successfully imported PowerShell Script written using C#, but it throws System.BadImageFormatException when i tried to execute it. After spending few hours, figured out my Powershell Script was compiled for x86, so i should have used “c:\Windows\SysWOW64\WindowsPowerShell\v1.0”.

Tuesday, 10 April 2012

Useful tips

1. How to load all the assemblies?

var loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies();

2. Combine absolute & relative paths

var relativePath = "..\\bling.txt";
var baseDirectory = "C:\\blah\\";
var absolutePath = Path.GetFullPath(baseDirectory + relativePath);

3. Get x86 Program folder

    static string ProgramFilesx86()
    {
       if( 8 == IntPtr.Size
       || (!String.IsNullOrEmpty(Environment.GetEnvironmentVariable( 
                "PROCESSOR_ARCHITEW6432"))))
       {
            return Environment.GetEnvironmentVariable("ProgramFiles(x86)");
       }

        return Environment.GetEnvironmentVariable("ProgramFiles");
    }

4. Delete a windows server

   sc delete [servicename]

5. Sometimes Server.Databases[name].Drop() will fail with 'Currently in use' error 
   or FailedOperationException. These scenarios we have to 'Server.KillDatabase()).

6. Script to create User with server admin role

 USE [master];
 GO
 CREATE LOGIN SimpleUser
    WITH PASSWORD    = N'SimpleUser',
    CHECK_POLICY     = OFF,
    CHECK_EXPIRATION = OFF;
 GO
 EXEC sp_addsrvrolemember
    @loginame = N'SimpleUser',
    @rolename = N'sysadmin';

7. Sn -T [assembly] to get PublicKeyToken.

8. Remove database(s) based on name

DECLARE @Temp TABLE (Id INT IDENTITY(1, 1), name nvarchar(max));
DECLARE @RowCounter INT;
DECLARE @i INT;

INSERT INTO @Temp select name from sys.databases where name like N'GS_81%'

SELECT @RowCounter = MAX(Id) FROM @Temp

SET @i = 1

DECLARE @DBDeleteByName NVARCHAR(max);

WHILE @i <= @RowCounter
BEGIN
    SELECT @DBDeleteByName = 'DROP DATABASE [' + name + ']'  FROM @Temp WHERE Id = @i

    EXEC sp_executesql @DBDeleteByName;

    SET @i = @i + 1;
END