How to execute exe file in a web application

First of all we need to understand that under the existing web request process mechanism you can not make any executable application that exists on the web server execute on your machine(client machine) by requesting web server through IE. If your requirement is anything like this then better use Citrix Presentation Server.

Having said that, if you want to execute any executable program from you web application then you can try below given code in you web page.
Note – the exe will run on the server machine not on the client and you would not get any GUI.

//C# code
ProcessStartInfo MyProcess = new ProcessStartInfo();
//path of the program exe file
MyProcess.FileName = @"c:\myprogram.exe";
//pass parameter if you’re executable require any command line argument
MyProcess.Arguments = @"anyparam";

Process.Start(MyProcess);

Licensing for ActiveX Components

There are 2 types of licensing schemes for ActiveX controls.

1.Design time – implemented using LIC Files.
2.Run time – implemented using LPK (License Package File) files.

If you are using licensed ActiveX control for the development purposes then you would need LIC file to load it in the development environment like Visual Studio or MS Access etc. And if you are using it in the web application then you would need LPK file to run it in the web browser like IE etc.

In every ActiveX control licensing is implemented by implementing methods of IClassFactory2 interface, which is built upon IClassFactory interface. These interfaces provide methods that are used for verifying licensing information during the instantiations of the control both in the design time as well as run time. Some of the methods are: GetLicInfo, RequestLicKey, andCreateInstanceLic etc.

Design-Time Licensing:

In the design environments like Visual Studio or MS Access etc, when you try to place ActiveX control on the form or web page or create instance of the control, one or more of these methods are called to verify the licensing information from the license file (.Lic file) and upon verification the control is instantiated.

Run-Time Licensing:

Run time licensing differs for execution environments like Visual Studio or MS Access etc and Internet Explorer. In case of VS, license keys of the ActiveX controls used in the application are embedded in the executable file (.exe file) of the application whereas for Internet Explorer license keys of ActiveX control are stored in the license package file(.Lpk file).

In case of Visual Studio or MS Access, run time licensing is almost same as design time licensing. During the execution of application licensing information embedded in the exe file is verified by one or more methods of IClassFactory2 interface against the licensing information stored in the controls used in the application.

In case of Internet Explorer, licensing scenario is bit different specially when you are distributing ActiveX control (see my earlier post on How to redistribute ActiveX control with Web Application
) due to following reasons:

1.ActiveX control is executed in the remote client machine where as the host application exists in the server machine.
2.Due to the openness of the delivered HTML source code, licensing information can not be embedded in the server response.

So, due to the above scenario, run time licensing is implemented with a new file called the license package file (or LPK file). This file can be included in any HTML page by using the object tag.
Example:

< OBJECT CLASSID="clsid:5220cb21-c88d-11cf-b347-00aa00a28331" >
< PARAM NAME="LPKPath" VALUE="LPKfilename.LPK" >
< /OBJECT >

Note- CLASSID is the class ID of ActiveX License Manager component.

The above mentioned object tag embeds ActiveX License Manager, which is a component of Internet Explorer 4.0 found in the Licmgr10.dll file. This component parses an .lpk file and extracts the license key for each corresponding CLSID in the file. Remember, this tag should be added before the codebase tag for the control distribution.
At run time, when Internet Explorer 4.0 is rendering an HTML page that contains ActiveX Controls, the License Manager calls the IClassFactory2::CreateInstanceLic method, passing the license key that it extracted from the .lpk file in order to verify that a control is licensed. If the license key matches the control's license, the control will be rendered on the page.
Note: - LPK file should exists at the root of the application in the hosting server. Although you can add multiple lpk files in the web page but only first one will be considered by IE. Licensing information of all the licensed controls used in a page should be added in a lpk file embedded in that page.

Create license package file (.lpk file):
LPK file can be created using a utility named License Package Authoring Tool (Lpk_Tool.exe) that can be downloaded from the download section of this blog.
The application is actually simple to use. When you start the application, it displays a combo box that lists all of the ActiveX Controls currently running on your computer. The next step requires that you choose the controls that you want to display on a given HTML page. You choose a control by highlighting it in the combo box and then clicking the Add button. Once you've selected all the controls that you want to display on a given page, you can create and save the actual .lpk file by clicking the Save & Exit button.

References:

http://msdn.microsoft.com/en-us/library/aa231198(VS.60).aspx
http://msdn.microsoft.com/en-us/library/aa751973(VS.85).aspx

How to improve performance of Windows XP

Following are some tips to improve performance of your Windows XP OS.

1. Use Disk Defragmenter utility - One of the easiest ways to boost up XP's speed is defragmenting your hard drive regularly. You can find this utility in the System Tools section in Accessories.

2. Use Disk Cleanup utility - Disk cleaning helps you to remove unwanted files and programs from your hard disk, which helps IO operations of Win XP. It can be used to remove temporary Internet files, remove downloaded program files, empty the Recycle Bin, remove Windows temporary files, remove optional Windows components and remove installed programs that are no longer in use.

3. Stop Windows Index Service - Windows XP by default indexes files on local and network drives to speed up the file search process. However, this slows the PC performance as it indexes files continuously. So if you don't use the service regularly it is better to disable the process.

4. Remove unwanted start-up program - Having too many program in the program startup list also slows down the booting process of Win Xp. Therefore remove unwanted program from the startup list by running "msconfig" utility and unselecting programs from the startup list.

5. Remove unused fonts - Installing too many fonts in your machine also slows down Win XP. Delete unnecessary fonts from fonts folder in the control panel.

How to View Source HTML of Modal Dialog Window

Its a known functionality of the windows opened using ShowModalDialog function of javascript that you can not view html source of a modal dialog window but its a problem during the development because you might need to view html source of the window for debugging.
Here is the simple solution of the problem...

Add following javascript code in your web page.

< script language="javascript" >
function showHTML()
{
d=window.open();
d.document.open('text/plain').write(document.documentElement.outerHTML);
}
< /script >

And add following html code anywhere in the body of the web page.

< input type=button value="View Source" onclick="showHTML()" >

Now when you will browse your modal window and click on the said button, the HTML source code of the modal window will open in another window.

Server error : "There is no web named"

Server error : "There is no web named" .If this Web site exists on the server, check to make sure the FrontPage Server Extensions are installed, and that you have permission to access the server.

Solution: There could be many reasons for this error and there are many solution/suggestions available online but in my case none of them proved helpful. I could resolve this problem just by removing the Host Header Name from my website.

Steps:-

1. Open Internet Information Services Console window.
2. Right click on the website and open the website properties.
3. Click on website tab and then click on advance button in the web Site Identification section.
4.Now from the Advanced Multiple Web Site Configuration window, you can delete the Host Header Name associate with the IP adderss or the Default value. Remember dont delete the entry itself but edit it to remove the Header Name.

How to access HEAD tag from content page in asp.net

Sometimes we need to access head tag of master page from it content page for adding element tags like style, base ect. from its content page.
There could be various ways to add head tag elements from content page. Here I have mentioned how to add meta,style and base tag in the header section.

1. Adding META tags are quite easy.Add following C# code in the page load method of the content page.

HtmlMeta metatag = new HtmlMeta();
metatag.Name = "keywords";
metatag.Content = "ajax";
this.Header.Controls.Add(metatag);

2. Adding Style tag

HtmlGenericControl styles = new HtmlGenericControl("style");
styles.Attributes.Add("type", "text/css");
styles.InnerText = "a { color: #003399; text-decoration: none;}";
this.Header.Controls.Add(styles);

it will be rendered like this:-

< style type="text/css" > a {color: #003399;text-decoration: none;} < /style >

OR if you have already added style tag in it, you can access in like a variable and update it.

like:- < style type=”text/css” runat=”server” id=”myStyles” >

then in the content page it can be accessed like -

myStyles.InnerText += "a {color: #003399;text-decoration: none;}";

3. Adding Base tag - Add following C# code in the page load method of the content page.

HtmlGenericControl Tag = new HtmlGenericControl("BASE");
Tag.Attributes.Add("target", "_self");
this.Header.Controls.Add(Tag);
-----------------------------------
Another inovative way to access and update headed section is just add asp ContentPlaceHolder control in the Head section of your master page and then it can be access just like other ContentPlaceHolders with placing content tag in your content page for adding elements in the Header of the page.

like in the Master page(PopUp.master):-

< head runat="server" >

< title >< /title >

< asp:ContentPlaceHolder runat="server" id="MyHeader" >

< /asp:ContentPlaceHolder >

< /head >

In the content page-

< %@ Page Language="C#" MasterPageFile="~/Popup.master" AutoEventWireup="true" CodeFile="popUploadFile.aspx.cs"
Inherits="PopUp_popUploadFile" Title="Attachments" % >


< asp:Content ID="Content1" runat="server" ContentPlaceHolderID="MyHeader" >

< style type="text/css" > a {color: #003399;text-decoration: none;} < /style >

< /style >

< /asp:Content >

How to redistribute ActiveX controls with Web Application

If your website using ActiveX control then it needs to be installed on the client machine to use the functionality your website is providing through this control. Generally when such functionality is browsed by the client, web browser prompts the user for the installation of ActiveX control if it does not exists on the client machine.
(note - the above discussed behavior is subjected to the web browser settings)

The standard way to redistribute ActiveX controls through web pages is to package the ActiveX control and every other required file into a CAB file. The CAB file should be published on a web site and the CODEBASE parameter of the OBJECT HTML tag must be used to specify the location from where the ActiveX control and the dependent files can be downloaded.

Example:

< object id="ctrl" width=472 height=327 classid="CLSID:19B50C95-6BB5-4DFD-B20C-5B9A61FA1C0D" CODEBASE="http://www.website.com/redistribution/ctrl.cab" >
< /object >

Microsoft IE versions 3.0 and later use the CODEBASE attribute of object HTML tag to detect which version of ActiveX Control is installed on a user's computer and download & install the newer version of ActiveX control from the location specified by CODEBASE onto the user's machine if user is using older version.

Example:

< object id="ctrl" width=472 height=327 classid="CLSID:19B50C95-6BB5-4DFD-B20C-5B9A61FA1C0D" CODEBASE="http://www.website.com/redistribution/ctrl.cab#version=9,0,115,0" >
< /object >

The numbers '9,0,115,0' specify which version of the ActiveX control is required to use web functionality it provides.

URL Rewriting error : is not a valid virtual path

Sometimes this error occurs when you are doing some url rewriting with RewritePath method. One of the many possible reasons for this error is that assigning complete url path as a internal rewrite path. Therefore pass relative rewrite url path as a parameter to the RewritePath function instead of complete url.
For example, in the below given code, statement 1 will produce error where as statement 2 will work fine.

1. HttpContext.Current.RewritePath("http://localhost/TestSite/default.aspx");

2. HttpContext.Current.RewritePath("/TestSite/default.aspx");