Welcome

Hello, Welcome to my blog. If you like feel free to refer others

Tuesday, 13 May 2014

Programatically setting up Physical Path Credential on IIS server for a virtual directoty

Below mentioned function will do the same for you. But only thing you need to do add the reference of Microsoft.Web.Administration dll on your project(7.0.0.0)

private void SetPhysicalPathCredential(string virDirName)
        {
            try
            {
                if (!String.IsNullOrEmpty(physicalPathCredentialUserDomain) && !String.IsNullOrEmpty(physicalPathCredentialUserUserName) && !String.IsNullOrEmpty(physicalPathCredentialUserPassword))
                {
                    using (ServerManager manager = new ServerManager())
                    {
                        Site defaultSite = manager.Sites["Default Web Site"];

                        // Read the data back from the updated configuration system, 
                        // then modify the Physical Path credential.
                        Application apps = manager.Sites["Default Web Site"].Applications["/" + virDirName];
                        VirtualDirectory appDir = apps.VirtualDirectories[0];
                        LogMessage("Setting up Physical Path Credential: " + virDirName);
                        appDir["userName"] = physicalPathCredentialUserDomain + "\\" + physicalPathCredentialUserUserName;
                        appDir["password"] = physicalPathCredentialUserPassword;
                        LogMessage("Successfully set up Physical Path Credential");
                        manager.CommitChanges();
                    }
                }
            }
            catch (Exception e)
            {
                LogMessage("ERROR: Error Setting up Physical Path Credential " + virDirName);
                throw e;
            }
            
        }

Windows Installer error like while running light.exe from WiX

Unregister vbscript.dll and jscript.dll from HKEY_CURRENT_USER to resolve this error:

1. Click on the Start menu, choose Run, type cmd and click OK
2. To unregister the VBScript engine, run this command:  reg delete "HKCU\SOFTWARE\Classes\CLSID\{B54F3741-5B07-11CF-A4B0-00AA004A55E8}" /f
3. To unregister the VBScript engine on a 64-bit OS, run this command:  reg delete "HKCU\SOFTWARE\Classes\Wow6432Node\CLSID\{B54F3741-5B07-11CF-A4B0-00AA004A55E8}" /f
4. To unregister the JScript engine, run this command: reg delete "HKCU\SOFTWARE\Classes\CLSID\{F414C260-6AC0-11CF-B6D1-00AA00BBBB58}" /f

5. To unregister the JScript engine on a 64-bit OS, run this command: reg delete "HKCU\SOFTWARE\Classes\Wow6432Node\CLSID\{F414C260-6AC0-11CF-B6D1-00AA00BBBB58}" /f

So here you just need to do depending your OS version(32bit/64bit) you need to run the appropriate command.


Once I did that, my build started working as expected.  I still do not know how this information ended up in HKEY_CURRENT_USER on my system, particularly because the same build worked correctly on the same machine a couple of days ago.  However, I am now back into a state where I can build successfully, and I know of a possible workaround to try if I end up with similar build issues in the future.

Hope this information will everyone who face this issue...... :)

Happy learning.......................................

Tuesday, 3 September 2013

Remove cache in asp.net

The following code will remove all keys from the cache:
public void ClearApplicationCache(){
    List<string> keys = new List<string>();
    // retrieve application Cache enumerator
    IDictionaryEnumerator enumerator = Cache.GetEnumerator();
    // copy all keys that currently exist in Cache
    while (enumerator.MoveNext()){
        keys.Add(enumerator.Key.ToString());
    }
    // delete every key from cache
    for (int i = 0; i < keys.Count; i++) {
        Cache.Remove(keys[i]);
    }
}


Modifying the second loop to check the value of the key before removing it should be trivial.
Hope this helps.

Wednesday, 31 July 2013

Asp.net Show Message box after saving the data into db server(sql)

I have a common class and one of my method is this one
using System.Web;
using System.Text;
using System.Web.UI;

/// <summary> 
/// A JavaScript alert 
/// </summary> 
public static class ShowAlertMessage
{

    /// <summary> 
    /// Shows a client-side JavaScript alert in the browser. 
    /// </summary> 
    /// <param name="message">The message to appear in the alert.</param> 
    public static void Show(string message,string pageurl)
    {
        // Cleans the message to allow single quotation marks 
        string cleanMessage = message.Replace("'", "\\'");
        string script = "<script type=\"text/javascript\">alert('" + cleanMessage + "');window.location='" + pageurl + "'</script>";

        // Gets the executing web page 
        Page page = HttpContext.Current.CurrentHandler as Page;

        // Checks if the handler is a Page and that the script isn't allready on the Page 
        if (page != null && !page.ClientScript.IsClientScriptBlockRegistered("alert"))
        {
            page.ClientScript.RegisterClientScriptBlock(typeof(ShowAlertMessage), "alert", script);
        }
    }

    public static void Show(string message)
    {
        // Cleans the message to allow single quotation marks 
        string cleanMessage = message.Replace("'", "\\'");
        string script = "<script type=\"text/javascript\">alert('" + cleanMessage + "');</script>";

        // Gets the executing web page 
        Page page = HttpContext.Current.CurrentHandler as Page;

        // Checks if the handler is a Page and that the script isn't allready on the Page 
        if (page != null && !page.ClientScript.IsClientScriptBlockRegistered("alert"))
        {
            page.ClientScript.RegisterClientScriptBlock(typeof(ShowAlertMessage), "alert", script);
        }
    }
}
then any time i want to display a message i just call that method from page like this.
ShowAlertMessage.Show("Data has been saved!");
hope that help.


Happy learning :)

Monday, 17 June 2013

Printing pyramid like stars using C#

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(Enumerable.Range(1, 7).Aggregate(new StringBuilder(), (sb, i) => sb.AppendLine(new string('*', 7 - 2 * Math.Abs(i - 4)).PadLeft(7 - Math.Abs(i - 4)))));
            Console.ReadLine();
        }
    }   
}

Output:






Wednesday, 24 April 2013

Use getElementById in Javascript to iterate through table

var SelectedRowsCount = new Array();
var AllRowsCount = new Array();
var HeaderCheckBox = new Array();

function CountCheckedRowsByCol(detailTableName, colNum)
{
    AllRowsCount[colNum] = 0;
    SelectedRowsCount[colNum] = 0;
   
    var detailTable = document.getElementById(detailTableName);
   
    if (detailTable == null)
        return;

    var Rows = detailTable.getElementsByTagName("tr");

    if (colNum == null)
        colNum = 0;

    for (i = 0; i < Rows.length; i++)
    {
        var cols = Rows[i].getElementsByTagName("td");
       
        if (cols.length <= colNum)
            continue;
       
        var chks = cols[colNum].getElementsByTagName("input");
       
        if (chks.length == 0)
            continue;
        if (chks[0].type != "checkbox")
            continue;
       
        if (AllRowsCount[colNum] == 0)
        {
            if (HeaderCheckBox[colNum] == null)
                HeaderCheckBox[colNum] = chks[0];
        }
        else
        {
            if (chks[0].checked)
                SelectedRowsCount[colNum]++;
        }
       
        AllRowsCount[colNum]++;
    }
   
    AllRowsCount[colNum]--;
   
//    alert(AllRowsCount[colNum]);
   
    //CheckHeaderIfAllColChkBoxSelected(colNum);
}

Thursday, 28 February 2013

Getting Access Denied error when using XMLHttpRequest in javascript on IE


This error could happen due to cross domain issue, use relative path in Server Url if using absolute, also you may try changing Internet Explorer Trusted Site Zones settings (Internet Explorer Options->Security-> Trusted Sites (if your Url added into Trusted Sites, if added into Local intranet then choose Local Intranet) -> Custom Level) , scroll down and change Access data sources across domains value to Enable

If the above does not solve problem then you may deploy clientaccesspolicy and crossdomainpolict xml to resolve the issue:http://msdn.microsoft.com/en-us/library/cc197955(v=vs.95).aspx




 Happy Learning.....