CONNECT WITH US

Featured Post

Import Apache mod_rewrite Rules in IIS 7

Get article update by Email

With Microsoft's Web Stack, many PHP applications are now hosted on IIS. As PHP is an open source, one of the advantages of using PHP is that you will find plenty of free script for ready to use. And basically these all ready to use scripts are written for LAMP model, so we might face some problem related to web server (Apache vs IIS) configuration while running these scripts on IIS. Recently one of my friend face similar problem with Apache rewrite rules while he deployed ready to use PHP script on IIS, and asked me to resolve it.

We need to convert apache mod_rewrite rules into IIS URL Rewrite rules to deploy PHP application on IIS. We can accomplish this task in two ways.

First way

Open .htaccess file of PHP and manually convert each apache mod_rewrite rule in IIS URL Rewrite rule and then save it in web.config. Now loop through above process for total number of apache mod_rewrite rule ;)

Smarter way

Instead of manually loop through each apache mod_rewrite rule and converting it in IIS URL Rewrite rule, we can automate this process with IIS URL Rewrite Module. Earlier in one post we have seen how we can use IIS URL Rewrite Module to set preferred domain. Following is the steps for converting apache mod_rewrite rules into IIS URL Rewrite rules.

Open URL Rewrite Module in IIS.

In Actions pane of right side, click on import rules. It will open Import mod_rewrite rules screen.

Browse through .htaccess file and click on import button.

You can see summary of converted rules in tree view. You can also verify converted rules in XML view.

After verifying each rule click on apply in Actions pane.

That’s it, you have done. Now your all apache mod_rewrite rules are converted in IIS URL Rewrite rule and saved in web.config.

Read More

IIS 7 Tutorial Posts Link

Get article update by Email
Read More

Build Online C# Syntax Checker with Roslyn

Get article update by Email

On 19th Oct, Microsoft released first Community Technology Preview of the Roslyn Project. With the release of Roslyn Project, First time Microsoft is opening up the C# and Visual Basic compilers through Rich Roslyn API. More detail about Core API and others feature of October CTP released can be found here.

As far as the web development concerns, Possibilities are lot increased with Roslyn project. In future we might see web application for online syntax checker-formatter, online code compiler (Upload code and download dll / assembly!!!), and might even whole online IDE based on SaaS model!!!

Possibilities are endless. Here we will see how we can create online C# syntax checker with the help of Roslyn.Compilers.CSharp.DiagnosticList class.

NOTE: Please note that Roslyn Project is a still in technology preview and there are known issues and only a subset of the VB and C# languages has been implemented at this time.

Create new web application with Roslyn (See my post on how to setup .NET project with Roslyn).

In default.aspx add one textbox, button, and label as below. And on button click event write following code.

protected void btnCheck_Click(object sender, EventArgs e)
{
    string strDetail = "";
    Diagnostic obj;
    var tree = SyntaxTree.ParseCompilationUnit(txtSyntax.Text);
 
    if (tree.GetDiagnostics().Count == 0)
    {
        strDetail += "Diagnostic test passed!!!";
    }
 
    for (int i = 0; i < tree.GetDiagnostics().Count; i++)
    {
        obj = tree.GetDiagnostics()[i];
        strDetail += "<b>" + (i + 1).ToString() + ". Info: </b>" + obj.Info.ToString();
        strDetail += " <b>Warning Level: </b>" + obj.Info.WarningLevel.ToString();
        strDetail += " <b>Severity Level: </b>" + obj.Info.Severity.ToString() + "<br/>";
        strDetail += " <b>Location: </b>" + obj.Location.Kind.ToString();
        strDetail += " <b>Character at: </b>" + obj.Location.GetLineSpan(true).StartLinePosition.Character.ToString();
        strDetail += " <b>On Line: </b>" + obj.Location.GetLineSpan(true).StartLinePosition.Line.ToString();
        strDetail += "</br>";                
    }            
 
    lblResult.Text = strDetail;
}

Code Explanation

DiagnosticList is a collection or list of Diagnostic class gives information which can be helpful to diagnosis any error if there is. Diagnostic.Info property gives various information which is helpful in diagnosis. For e.g. Error code, Warning Level, Severity Level, Message, etc. whereas Diagnostic.Location property give information which can be helpful to identify error location. For e.g. line no, character position, source file or metadata error and lot more.

Sample Output

Read More

Setup .NET Project with Roslyn

Get article update by Email

Yesterday Microsoft released first Community Technology Preview of the Roslyn Project. With the release of Roslyn Project, First time Microsoft is opening up the C# and Visual Basic compilers through Rich Roslyn API. More detail about Core API and others feature of October CTP released can be found here.

In this post we will see how to setup .NET project with Roslyn.



Prerequisite

Visual Studio 2010 SP1 SDK (Download it here)
Microsoft “Roslyn” CTP (Download it here)

Setup Project with Roslyn

Create new project (Web / Console / Windows)

From Project menu click on Add Reference, it will open Add Reference dialog box.

You need to add reference to Roslyn.Compilers and Roslyn.Services.CSharp or Roslyn.Compilers.VisualBasic depending upon your project language C# or Visual Basic.

You can find these assemble under .NET tab of Add Reference dialog. Add reference to appropriate assembly as listed above.

In case if you do not find above assembly under .NET tab then navigate to Browse tab and look in C:\Program Files\Reference Assemblies\Microsoft\Roslyn\v1.0 directory. By default all Roslyn assembly are placed at that location.

That’s it, you have done!!! You can now leverage the rich Roslyn API to build application or extensions based on Roslyn.

Read More