Tech NovoGeek

...Technology Simplified

Thursday, July 26, 2012

It is not possible to run two different versions of ASP.NET in the same IIS process

No comments :

Server Application Unavailable

The web application you are attempting to access on this web server is currently unavailable.  Please hit the "Refresh" button in your web browser to retry your request.

Administrator Note: An error message detailing the cause of this specific request failure can be found in the application event log of the web server. Please review this log entry to discover what caused this error to occur.

You will also receive Event ID 1062 in Event Viewer that says:

"It is not possible to run two different versions of ASP.NET in the same IIS process. Please use the IIS Administration Tool to reconfigure your server to run the application in a separate process."

image

The simple solution for this is:

Create a new application pool and move the site that you will be upgrading to that pool. Once you have placed the site or virtual directory in new application pool, then upgrade to the new framework version.

Follow the below steps to create resolve this issue:

image

 

image

U1ntitled

Wednesday, July 11, 2012

Windows Service -- creation , Installation , Uninstallation

No comments :

In this post we will have a look at how to create windows service in c# and how to install or uninstall and how to start service in detail.
First let us know what a window service is and uses of windows service and then we will see how to create windows service.

What is Windows Service?

Windows Services are applications that run in the background and perform various tasks. The application that does not need any user interface. Windows Services are started automatically when computer is booted. Windows Services are controlled through the Service Control Manager where they can be stopped, paused, and started as needed.

How to Create a Windows Service

Open visual studio (I’m using Visual studio 2010) --> Select File --> New -->Project--> select Windows Service from c#

clip_image002

click ok button to create our project that should like this

clip_image004

In Solution explorer rename Service1.cs file to SampleService.cs.

And then right click on the page to select Properties then change ServiceName to SampleService.

clip_image005

Open SampleService.cs in design view and right click on it to Add Installer files to our application. The main purpose of using Windows Installer is an installation and configuration service provided with Windows. The installer service enables customers to provide better corporate deployment and provides a standard format for component management.

clip_image006

You can now see two controls: ServiceProcessInstaller1 and ServiceInstaller1

Now right click on serviceProcessInstaller1 and select properties in that change Account toLocalSystem

clip_image007

Now right click on ServiceInstaller1 and change properties

StartType to Automatic

DisplayName to ‘SampleService’

After completion of setting all the properties now we need to write the code to run the windows services.
We implement windows service to write entry every minute into a file.
If you observe our project structure that contains Program.cs file that file contains Main() method otherwise write the Main() method like this in Program.cs file

using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceProcess;
using System.Text;

namespace WindowsService1
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main()
{
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new SampleService()
};
ServiceBase.Run(ServicesToRun);
}
}
}
Open SampleService.cs file and add namespaces for writing to file and timerin codebehind of SampleService.cs file

using System.IO;
using System.Timers;
  public partial class SampleService : ServiceBase
{
Timer timer = new Timer();

public SampleService()
{
InitializeComponent();
}

protected override void OnStart(string[] args)
{
TraceService("start service");
timer.Elapsed += new ElapsedEventHandler(OnElapsedTime);
timer.Interval = 60000;
timer.Enabled = true;
}

protected override void OnStop()
{
timer.Enabled = false;
TraceService("stopping service");
}

private void OnElapsedTime(object source, ElapsedEventArgs e)
{
TraceService("Another entry at " + DateTime.Now);
}

private void TraceService(string content)
{
FileStream fs = new FileStream(@"C:\SampleService.txt", FileMode.OpenOrCreate, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs);
sw.BaseStream.Seek(0, SeekOrigin.End);
sw.WriteLine(content);
sw.Flush();
sw.Close();
}
}
In OnStart method the event ElapsedEventHandler is used to run the windows service for every one minute
Then build the application and install the service.
To install windows service in your follow these steps
Start --> All Programs --> Microsoft Visual Studio 2010 --> Visual Studio Tools --> Open Visual Studio Command Prompt
After open command prompt point to your windowsservice1.exe file in your project

clip_image009
Installutil windowsservice1.exe (Give your windows service exe file name) and now press enter button.

clip_image011

After successful installation of service, to view it:
Start --> Control Panel --> Open Control Panel --> Select Administrative Tools --> Computer Management --> Services and Applications --> Services --> Open services

clip_image013
Right click on sampleservice and start the service.
Note: If we want to uninstall the installed windows service go to VS 2010 command prompt and point to your service same as for installation and type statement installutil /u windowsservicesample.exe
Once the service is started, and you will be able to see entries in the log file we defined in the code.

Now open the log file in your folder that Output of the file like this

image

XSLT transformation using Windows Service

No comments :

private string ArchivePath = @"c:\Archive\";
private string InputPath = @"c:\InputFiles\";
private string OutputPath = @"c:\OutputFiles\";
To write the exception entries to Event Viewer

protected override void OnStart(string[] args)
{
Transformation();
try
{
// Uncomment this line to debug...
//System.Diagnostics.Debugger.Break();

_thread = new System.Threading.Thread(Transformation);
_thread.Start();
EventLog.WriteEntry("Successful start.", EventLogEntryType.Information);
}
catch (Exception ex)
{
// Log the exception.
EventLog.WriteEntry(ex.Message, EventLogEntryType.Error);
}
}


private void Transformation()
{
System.IO.Directory.SetCurrentDirectory(System.AppDomain.CurrentDomain.BaseDirectory);
// Source paths
string xsltFilePath = "D:\\Transformation.xslt";
// refer link http://technovogeek.blogspot.ie/2012/07/how-to-display-current-date-and-time-in.html for using sample XSLT
// Compile the style sheet.
XsltSettings xslt_settings = new XsltSettings();
xslt_settings.EnableScript = true;
XslCompiledTransform xslt = new XslCompiledTransform();
xslt.Load(xsltFilePath, xslt_settings, new XmlUrlResolver());
try
{
string[] inputfileEntries = Directory.GetFiles(InputPath);
foreach (string fileName in inputfileEntries)
{
// Load the XML source file.
XPathDocument doc = new XPathDocument(fileName);

// Create an XmlWriter.
XmlWriterSettings settings = new XmlWriterSettings();
settings.OmitXmlDeclaration = true;
settings.Indent = true;

if (!System.IO.Directory.Exists(OutputPath))
System.IO.Directory.CreateDirectory(OutputPath);
string file = System.IO.Path.Combine(OutputPath, System.IO.Path.GetFileNameWithoutExtension(fileName) + "_OUTPUT.xml");

XmlWriter writer = XmlWriter.Create(file, settings);

if (!System.IO.Directory.Exists(ArchivePath))
System.IO.Directory.CreateDirectory(ArchivePath);
string destFile = System.IO.Path.Combine(ArchivePath, System.IO.Path.GetFileName(fileName));
System.IO.File.Copy(fileName, destFile, true);
// Execute the transformation.
xslt.Transform(doc, writer);
writer.Close();
System.IO.File.Delete(fileName);
}
}
catch (Exception ex)
{
string str = "Unable to process the Conversion ";
}
}

How to display current Date and Time in XSLT using C#

No comments :
<?xml version="1.0" encoding="iso-8859-1" ?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:my="put-your-namespace-uri-here"
exclude-result-prefixes="msxsl my">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<msxsl:script language="C#" implements-prefix="my">
public string NowDate(){
return DateTime.Now.ToString("ddMMyyyy");
}
public string NowTime(){
return DateTime.Now.ToString("hhmmss");
}
</msxsl:script>
<xsl:template match="/">
<xsl:value-of select="my:NowDate()" />
<xsl:value-of select="my:NowTime()" />
</xsl:template>
</xsl:stylesheet>