Rajeeshcv.com

Sharing my knowledge

Visual Studio : Debugging Silverlight Application with Chrome and Firefox

Here is a tip if you want to debug Silverlight applications from Visual Studio 2012 if it is running in Google Chrome or Firefox

Google Chrome

  1. Run the application and select Debug –> Attach to Process from the menu
  2. From the Available Processes list, look for process named “chrome.exe” with type “Silverlight”
  3. Select that process and click the “Attach” button

Here is screenshot from my machine

Mozilla Firefox

Firefox has a slightly different approach

  1. Run the application and select Debug –> Attach to Process from the menu
  2. From the Available Processes list, look for process named “plugin-container.exe”
  3. Select that process and click the “Attach” button

Here is the screenshot

Voila!!! now you are able to get the breakpoints in Visual Studio

One of the Top E-Commerce Website in India Stores Passwords Incorrectly

Disclaimer: I am not a security expert nor a hacker, but just a developer.

This incident made me feel very bad – couple of weeks before I ordered a product from naaptol a well-known E-Commerce website in India.  It was the first time I was ordering something from them. So I had to register first, after the registration was completed got a confirm email from them

Oops!!! My password is in clear text.

I thought they might be generating the email during the registration process before it is stored in their database. Without bothering much, I ordered the item. Thought about investigating about the “clear text password” little bit, but somehow forgot it.

After few days when I got the product which I have ordered, it reminded me about this password incident. So in order see whether they are hashing my password or not, I used their “Forgot my password” option. It asked for my email address. After the submission got a message saying

We' have sent you an e-mail at the submitted ID including instructions. You'll be back to your shopping place in no matter of time.

As expected, got an email from them

It reads “Here is your new Login and Password” and surprisingly password they gave is same as my old password even though in the email it is mentioned that they are sending a new password. It confirmed that they are not hashing the passwords.

Will they be storing it in plain text? Who knows…

Did someone tell you internet is not a good place to store your secrets?

I tried to play a nice role, so sent them an email telling about about the password hashing problem. You know what happened… no reply from them till now.

If you are in the naaptol technical team, convince your boss about the importance of securing the password and push that functionality in the next release.

If you are a non-technical manager in naaptol, tell your developers to read this article from Jeff - You're Probably Storing Passwords Incorrectly

Automating WYSIWYG editors using Selenium web driver

Automating web application using selenium for acceptance/integration tests is very easy. Recently I have faced few issues when automating a page with a JavaScript based WYSIWYG editors.

The reason why it is hard because most of these editors create a new editable HTML document inside an iframe. There are two ways I aware that you can set text on these editors

  1. Executing a JavaScript code in the current page
  2. Sending keys on the editable iframe

Here is how I automated two WYSIWYG editors using selenium web driver.

bootstrap-wysihtml5


private void SetBootstrapWysihtml5Content(IWebElement textArea, string content)
{
    string script = string.Format(@"$('#{0}').data('wysihtml5').editor.setValue('{1}');", textArea.GetAttribute("id"), content);
    ((IJavaScriptExecutor)this.WebDriver).ExecuteScript(script);
}

What this method does is, it accepts the TextArea web element which you are converting to an editor and the actual content to be set. Then it executes a piece of JavaScript on the current WebDriver context.

For e.g. if you have a TextArea element with id “summary” then executing below JavaScript statement will insert a “Test” as h1 tag to the editor

$('#summary').data('wysihtml5').editor.setValue('<h1>Test</h1>');

TinyMCE

private void SetTinyMCEContent(IWebElement textArea, string content)
{
    string textAreaId = textArea.GetAttribute("id");
    string frameId = string.Format("{0}_ifr", textAreaId);
    var frame = this.WebDriver.FindElement(By.Id(frameId));
    this.WebDriver.SwitchTo().Frame(frame);
    ((IJavaScriptExecutor)this.WebDriver).ExecuteScript("document.body.innerHTML = '" + content + "'");
    this.WebDriver.SwitchTo().DefaultContent();
}

This method also accepts the TextArea web element which you are converting to an editor and the actual content to be set. Then it finds the corresponding iframe and set the innerHTML by executing a JavaScript statement.

Workaround for Web Essentials to support TypeScript 0.8.1.0

If you have installed the latest version of TypeScript(0.8.1.0) ,  Web Essentials extension you have installed on the VS 2012 may not be working correctly. Here is a work around to get it working

  1. Open command prompt as an administrator and go the TypeScript installation directory. In my case it is C:\Program Files (x86)\Microsoft SDKs\TypeScript.
  2. If the older version of TypeScript (0.8.0.0 or below) is there in that directory, delete it
    Create a symbolic of the older version, which points to the new version using the following command
    mklink /D 0.8.0.0  0.8.1.0
  3. Now open VS 2012 and go to Tools -> Options -> Web Essentials -> TypeScript. Set “Compile all TypeScript files on build” to “False”

Introducing SourceCodeReader

Have you ever tried to understand a project just by going through the source code?

That’s how I do most of the time, till now I haven’t seen any up to date documentation which gives the clear understanding of how the code is implemented. In reality after a certain period during the development, documentation goes out of sync with the source code. So some one joins the project lately has only one way to understand the project “Go through the source code

Sometimes I go through the open source projects hosted on either Github, Codeplex or Google code. All the hosting site provide you with a user interface for browsing through the source code with syntax highlighting support, which is nice. The problem I had with this is – if I see a object creation statement, method call there is no way for me to find out how it is implemented other than manually going through the files and finding it out.

Most of the full blown editors provide a feature where you can navigate to the implementation directly from where it is used for e.g. Microsoft Visual Studio provides “Go To Definition” feature. I find this feature very much useful for understanding the project. Only draw back with this approach is you have to completely get the latest version of source code to your local machine.

SourceCodeReader is trying solve this navigation problem on the web. With this application you can open a project and browse through the files with code navigation support.

Source code for this project can be found at https://github.com/cvrajeesh/SourceCodeReader

Limitations

  1. Now supports only Github code repository
  2. Only supports .Net C#  projects, other type of projects also works without code navigation support

* Caution: This is an early release you will see bumpy roads.

 

How to use this application

 

Go to SourceCodeReader and enter the URL of a C# project on Github

image

 

Once you have entered a Github project link and open the project, it get the source code from the Github and present you with file browser.

image

 

When you navigate to a C# file you will be able to see clickable links for identifiers which takes you the file location where that is declared.

image

 

Sample projects

  1. http://sourcecodereader.apphb.com/#/open/cvrajeesh/SourceCodeReader
  2. http://sourcecodereader.apphb.com/#/open/ayende/ravendb

Hope you liked this idea, please provide me with your valuable feedback.

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

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

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

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

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...