Rajeeshcv.com

Sharing my knowledge


Attach to Any ASP.NET Web Server from Visual Studio in One Click

Posted on: 30 Nov 2011 | Filed under: VisualStudio, ASP.NET, .NET | comments (3)

This is an update to my previous blog post Attach to Visual Studio Development Server with One Click.

The Visual Studio Macro from previous article doesn’t support IISExpress or IIS; it only supported the Visual Studio Development Server, more over it doesn’t detect latest Development Web Server “WebDev.WebServer40.exe”.

Now I have updated the Macro so that it will automatically detect the Web Server setting from the project properties and attach it accordingly.

Read more...

Attach to Visual Studio Development Server with One Click

Posted on: 26 Nov 2011 | Filed under: ASP.NET, .NET, VisualStudio | No comments yet

Update: Enhanced version of the Macro created here is available in the new article -  Attach to Any ASP.NET Web Server from Visual Studio in One Click

In my day to day work, during the development I had to attach an ASP.NET application to the development server (Cassini) several times in order to debug and fix a problem.

This task is little bit time consuming because this is how we normally do it

  1. Click on the “Attach to Process” menu under the Debug menu
  2. Select the correct process from the list of available processes
  3. Either double click on the select process or click the “Attach” button

You can reduce these into two steps, if you assign a short cut key to the “Attach to Process” command.

What I found is most of the time is lost in finding and selecting the correct process from the available list of processes in the “Attach to Process” dialog.

Read more...

Multiple visual studio development servers while debugging

Posted on: 24 Nov 2011 | Filed under: .NET, ASP.NET | No comments yet

You might have noticed that when you start debugging an ASP.NET web application, it start more than one visual studio development servers and in the system tray you see something like this

Mutiple_development_server

This happens when your solution contains more than one web application, setting one as the StartUp project is not going to help..

The reason for this is - by default any web application is set to start when we trigger the debugging process in visual studio. We need to disable that auto start feature so that only one visual studio development server is getting started when we are debugging.

These are the steps for disabling it

  1. Select the web project which you don’t want to start
  2. Go to the properties window (Shortcut – press F4)
  3. Set “Always Start When Debugging” to False

Disable_Start_When_Debuggin

This is how you could do it in Visual studio 2010, I hope the same applies to Visual studio 2008 too. Now if you start debugging, you will see only one development webserver.

Hope this helps


Abstractions can also put you in trouble

Posted on: 19 Nov 2011 | Filed under: NHibernate, .NET | No comments yet

We all have enjoyed the beauty of abstracting out functionality, so that it simplifies the underlying complexity. Sometimes it can come back and hit you on the forehead like a boomerang if we don’t know what is going underneath those hidden layers.

Recently it happened to me with the LINQ provider. If you have a data source then you can build your own Query provider on top of it, so that the users can access your data using the LINQ statements without understand how it is fetched.

For e.g. Linq2Twitter it provides the IQueryable interface which you can use fetch the twitter API without understanding the REST API’s exposed by the Twitter.

Similarly Ayende has created a Linq provider for NHibernate (NHibernate.Linq) which hides complexities of writing Criteria API’s.

This is what happened to me – we had a repository method which is using the NHibernate.Linq and it returned an IQueryable interface of domain model.
Like to the below code(only an example, this is not from the actual codebase itself)

public IQueryable<Customer> QueryableCustomers()
{
    session = SessionFactory.OpenSession();
    return session.Linq<Customer>().AsQueryable();
}

 

In the consumer part (Action method in the controller), we are filtering the customer with a name containing particular string using the Contains method

this.dataProvider.QueryableCustomers().Where(x => x.Name.Contains("custo")).ToList();

 

Everything worked as expected, but one day the filtering stopped working, I couldn’t figure it out initially, but when I looked into the “QueryableCustomers()” method, it has been changed to something like this

Read more...

How to move directories across SVN repositories

Posted on: 15 Nov 2011 | Filed under: General | No comments yet

Recently we were restructuring our project repositories, where I had to move a project from it’s own repository to another repository.

When do a move under SVN you need to make sure that the history is not lost, so I will explain two common scenarios and how you could do the SVN move

Scenario 1 - Moving files or directories with in a SVN repository


Below is a screen shot of my existing repository and I want to move the configuration directory to the project  directory without loosing the history.

Screen1

First of of all this will work only for the versioned items, so please commit your changes to the directory you want to move before doing this. The steps explained below assumes that you are using Tortoise SVN

Read more...

Stay away from Request.Url

Posted on: 30 Oct 2011 | Filed under: .NET, ASP.NET, MVC | comments (1)

The title might be misleading but I will explain why we shouldn’t use the Request.Url in any asp.net application directly.

If you are writing an web application and you don’t where it is going to be deployed, environment of the server where it is getting deployed, then it is better not to use Request.Url it directly.

image

This blog is running on a home grown blog engine, which is written using asp.net MVC 3. For implementing some of the functionalities like generating sitemap.xml I had to get the root of the url(i.e. without any path). So I used the Request.Url.GetLeftPart(UriPartial.Authority) method and it worked perfectly on my local machine even when it is deployed my local machine IIS server. When I deployed my blog engine to Appharbor environment, the generated sitemap.xml has a URL with port number like http://www.rajeeshcv.com:4566 instead of just http://www.rajeeshcv.com.

Read more...

New outlook–rolling out my own blog engine

Posted on: 27 Oct 2011 | Filed under: General | comments (4)

For the last couple of years I was using wordpress as my blogging platform, it is an awesome framework but finally I decided to move away from it and created my own blog engine(Rhyble), on which this blog is running now.

Rhyble is built using Asp.Net MVC3, NHiberanate and it is running Appharbor

image

You might ask why I want reinvent the wheel again because we have many blog engines available today.

Jeff Atwood answered that question here - Why does every man and his dog want to code a blogging engine?

 

These were my objectives when I started creating Rhyble

  • Focus on the most important functionalities, doesn’t want to create another wordpress with truck full of unwanted things
  • Improve the performance. Now I have YSlow rating of 94 compared to 65

image 

  • I didn’t wanted to go through the existing blog engines code base, which is more time consuming than creating a new one

More over it is a nice feeling if you have something you own. Now I have platform of my own and next things should be blogging frequently.

That’s it for the day.


Web Usability– avoid an extra page load with OpenSearch.

Posted on: 05 Apr 2011 | Filed under: General, Web | Tagged under: General | No comments yet

Now a days most of the websites, blogs or any applications that are on internet will have a search functionality which is great!!!. Before the Omnibox concept was introduced by google chrome, if we want to search something in google, as a user I need to go to www.google.com and type the search query. After the introduction of Omnibox, user don’t need to open the google website instead you could do the search from the address bar itself. From the usability point of view, it is a great functionality IMHO.

From the point of google search application, they have done it smartly. As a web developer how could you provide the same usability feature to your own website. Some of the website I frequently visits has done like this.

http://www.stackoverflow.com 

clip_image001

If you are in google chrome, after you type the stackoverflow.com a message will be displayed on the address bar saying that “Press Tab to search Stack Overflow”. If you press tab, you can directly type the search query in the address bar itself and pressing enter will show the results. This basically allows you to do a quick search, instead of going to the website and finding the search box and pressing search button(a long process is it? Smile)

Read more...

MVC - Rendering view elements in a specified order

Posted on: 27 Feb 2011 | Filed under: .NET, MVC | Tagged under: ASP.NET, MVC | No comments yet

In my current project, I had to render elements in the view based on a setting provided by the model(basically it is a configurable thing). Few clients need view element to be rendered in a particular order and few others in a different way. What we did was, saved this elements order in a settings file which could be changed based on the clients. Then created an extension to render this based on the order.

This is what was I was trying to explain. for  Client 1 the “Login section” to be displayed first followed by “Password reminder section

image

For Client 2 , these sections needs be ordered differently

image

In order to achieve this, I came up with an HtmlHelper extension

/// <summary>
/// Renders the render items in the provided sequence order.
/// </summary>
/// <param name="htmlHelper">The HTML helper which is extended.</param>
/// <param name="sequenceOrder">The order in which items to be rendered. Sequence starts at an index of 0.</param>
/// <param name="renderItems">The items to be rendered in order.</param>
/// <remarks>
/// Values in the sequence order should match with the total number of render items. 
/// Invalid sequnce numbers are ignored.
/// </remarks>
public static void OrderBy(this HtmlHelper htmlHelper, int[] sequenceOrder, params Action<HtmlHelper>[] renderItems)
{
    if (sequenceOrder != null && renderItems != null)
    {
        foreach (var sequnce in sequenceOrder)
        {
            // CHeck whether the sequence is with inthe bounds
            if (sequnce < renderItems.Length && sequnce >= 0)
            {
                renderItems[sequnce].Invoke(htmlHelper);
            }
        }
    }
    else if (renderItems != null)
    {
        // If the sequence order is not provided, render it in normal order in which items are declared.
        foreach (var renderItem in renderItems)
        {
            renderItem.Invoke(htmlHelper);
        }
    }
    else
    {
        // Do Nothing
    }
}

In the view, you could do

<% Html.OrderBy(this.Model.LoginDisplayOrder, (html) => { %>
    <div class="container"></div>                
    <% Html.RenderPartial("LoginSection", this.Model); %>
<% }, (html) => { %>
    <div class="container"></div>
    <% Html.RenderPartial("ReminderPassword", this.Model); %>
<% }); %>

Here Model.LoginDisplayOrder is just an array of integers in which the items to be rendered. Hope this will help.