Quick tip: Publishing a web application with MSBuild

We have this project, that is developed in house and at an outside contractor. Recently, we purchased and installed BuildMaster and tried to use it to automatically publish this project as well. As it occurs, it is not as easy to publish a .NET 3.5 web application as it is from Visual Studio.

To cut the long story short… After several hours of research, hair pulling and quiet swearing, I found a solution that works. So, if you want to publish a web application with references to another project with MSBuild, you need to run it like this:

cd /D x:\Source\myApp\
c:\Windows\Microsoft.NET\Framework\v3.5\MSBuild.exe /target:ResolveReferences;_CopyWebApplication /p:Configuration=Release;WebProjectOutputDir=X:\Builds\myApp\;OutDir=X:\Builds\myApp\bin\ myApp.csproj

Then, just move the contents to final destination.

Developing for SQL Server merge replication

Lately, we’ve been pushing our application from single server environment into an environment with merge replication. Not only that, but we also migrated from another RDBMS to Microsoft SQL server. While application had no issues working in replication environment, I learned the hard way there are some things that I could and should have done better. This are my findings.

[Read the rest of this entry…]

Quick tip: Creating multiple user controls with simillar properties

Imagine you just created 4 or 5 or n different Web user controls in your ASP.NET WebForms application. Now you realized that they all share some properties. This is a problem, because it means you are having nearly identical code in multiple spots. What you can do is create a partial public class that inherits from System.Web.UI.UserControl class and put in all properties that your controls share. Then go to each and every of your user controls and change inheritance to your own class instead of System.Web.UI.UserControl.

Class from which your controls inherit:

public partial class MyControl : System.Web.UI.UserControl
{
	#region Properties

	public string Title { get; set; }
	public string Singature { get; set; }

	#endregion
}

This is how you use it in your controls (red represents original line):

public partial class MyControl1 : MyControl
{
	protected void Page_Load(object sender, EventArgs e)
	{

	}
	...
}

public partial class MyControl2 : MyControl
{
	protected void Page_Load(object sender, EventArgs e)
	{

	}
	...
}

And now, you can do something like:

<mytag:mycontrol ID="mc1" runat="server" Title="My title" Signature="Lotushints" />

for every control that inherits MyControl class

Microsoft cuts passwords to 16 chars

This week a big news broke out. Web mail service Hotmail apparently cut passwords to 16 character of length for years, despite allowing users to enter unlimited number of characters. According to arstechnica.com this applies to all Microsoft online services, i.e. Passport authentication.

Now, this in itself is not a worry. Allowing 16 characters is plenty and secure enough to not allow a brute force attack. Even by using rainbow tables an attacker would be helpless. However, to implement a maximum 16 character password one would either have to implement this password policy from start up or one would have to store passwords in plain text. The first one is not a worry, however, the second one suggest plain text passwords, which are a no-no and something that even a HelloWorld programmer should never do. Ever!

Personally I use Hotmail services since 1998 and, to be honest, I never had any problems using it. So, I can make an assumption, that passwords were trimmed to 16 character length and then protected by whatever protection is used by Microsoft. Hence, the news is only of sensational value.

Version 2.0

When I started this blog, a page theme was the last thing on my mind and to be honest, I thought a generic one would do. As more time passed, I started noticing things that I really didn’t like. For instance, a search window was a background image and cursor was not centered. Or the fact that the site corrupted in an instant someone had different font size. Thus, as you might have noticed in recent days, the site got a long needing and deserving design and content overhaul. Lord and behold, what you are seeing now is my first ever custom WordPress theme named Lotushints (how original).

Idea was to get rid of that early 2000s rich web site outlook and go for pure simplicity. Also, I wanted to organize articles a bit. Thus, categories were reduced from 20 (!) down to 3:

  • Tech stuff – where all technical and development articles are located;
  • Geekland – where you can find my rants, observations and interesting things from tech world outside software development;
  • Book reviews – for occasional rant or recommendation about books I read and found worthy writing about.

All three categories found place in main navigation as well, which meant I could scratch Categories section from right sidebar. I also decided to put entire blog archive in the main navigation as it is way too long to act as a normal sidebar item. All that sidebar item scrapping meant that I could easily move from two sidebar layout to only one, which leaves more space for articles.

That’s it really. I would really like to hear your opinions though.

Quick tip: Templated controls

If you create a templated server control, import it into your web-site or web application and you want to do:

<my:Control ID="myControl" runat="server">
   <ItemTemplate>
      Some text, html or whatever.
   </ItemTemplate>
</myControl>

and you are allowed to do only:

<my:Control ID="myControl" runat="server" />

you need to modify your ItemTemplate property to look like this:

[TemplateContainer(typeof(MyTemplateControl))]
[Browsable(false)]
[PersistenceMode(PersistenceMode.InnerProperty)]
public ITemplate ItemTemplate {
   get { ... }
   set { ... }
}

Generics

For years, I have tried to learn more about generics, but since my work was never in need for such implementation, I never bothered. Finally, an opportunity arose. I cannot go in specific details, but I had to write a Windows service (in C#) that daily obtains vast amount of similar data which must then be written to half a dozen tables of exactly the same structure. At this point, I would like to add, that amount of data obtained and amount of destination database tables are due to change at any point in future.

 

What are Generics?

According to Microsoft MSDN site “Generics allow you to define type-safe classes without compromising type safety, performance, or productivity. You implement the server only once as a generic server, while at the same time you can declare and use it with any type”. In reality this translates to the fact that if you must implement a class or function that needs to do same thing for different types, you can only write it once.

In .NET world, most of us use Generics daily, without knowing it. They are disguised as lists, collections and dictionaries.

[Read the rest of this entry…]

Clean code by Robert C. Martin

There are authors that suit you and there are authors that don’t. Having spent a decent amount of time to get through Clean Code: A Handbook of Agile Software Craftsmanship, I have found out, that Mr. Martin fails to suit me. His self admiration and belief that he is new software messiah (and as such, cannot be mistaken) is intolerable to the extent, when I literally had to convince myself from chapter to chapter to read the book until bitter and inconclusive end.

[Read the rest of this entry…]

.NET Custom validators – perfect tool (almost)

I don’t know about you, but working with .NET validators is always a fiddly job. Sure, they enable you to do quick validations, but I am yet to find an app where each field only needs one validator. And this is where things usually get interesting.

[Read the rest of this entry…]

Happy New Year

This year’s post count is getting a +1.

I wish you all a belated merry Christmas and a really happy, healthy and successful new year 2012.