Introducing jBlogMvc


Long time no posts, well I was studying Sharepoint 2007 technologies and actually started a series for development a while ago I just managed to write two  introductory posts and didn't write more I have some ideas I'd love to share in sharepoint development which I hope to write about them some time in the future and complete the series. However, recently the new ASP.NET MVC framework has gathered some fame and actually I too got attached to it and I am keen to learn new technologies and so, also the jQuery javascript library has been the choice of most the .NET web developers community.

Its Time to Learn

So, I have read alot of blogs and articles on ASP.NET MVC which has a massive amount of resources (while not being beta yet), I also read the excellent book "jQuery in Action" and learned a lot from it I do recommend it for learning jquery. Now its time to utilize this learning in a simple application that experience the stuff I read about, then I stumbled across this article Want To Learn Web Programming? Write A Blog Engine so be it, I will build a (Simple-Fully featured) blog engine in order to learn more and use these two new kids on the block.

Of course, I will use ASP.NET MVC, jquery and finally I will use Sql Express as the datastore and Linq to Sql for dal.[more]

Where I learn from

Before starting building my blog series I would like to share the blogs I read to learn from ASP.NET MVC

  1. Storefront MVC Series by Rob Conery.
  2. Stephen Walther Excellent MVC Tips and Forum series.
  3. Of course Scott Gu's mvc announcements and demos.
  4. Phil Haack blog.
  5. Steve Sanderson
  6. Emad Ibrahim the creator of Yonkly the open source twitter clone built on ASP.NET MVC and jQuery.
  7. Matt Hawley
  8. ASP.NET MVC tagged articles on DotNetKicks
  9. The Official ASP.NET MVC forums.

Let's start

So, what's jBlogMvc? its a small blogengine I am going to build in an agile process, jBlogMvc if you haven't notice j stands for jQuery, Blog for the engine itself  and Mvc for the ASP.NET MVC. I say here that this engine will be simple and complete I will try to add features as much as possible and build it in an extensible way like modern blog engines to enable themes, widgets and plugins. Also I need to point that the work on this blog engine is totally inspired from the great open source blog engines which include BlogEngine.NET, WordPress and other non blog engines as yonkly and many others.

What will part 0 cover ?

Other than announcing the blog engine, in this part I will have a version 0 that will have the following:

  • Vistor
    • Viewing posts By Chronological order.
    • Viewing individual posts.

Ok show me some code!

Too much talking lets get to the code now, ok the solution is as shown in the figure consisting of the following :


The database

For this ZERO part I didn't include much for the blog engine, the only table I included is the Post table as shown below, I do believe this table will be expanded more by time and more parts in the series.




public static void RegisterRoutes(RouteCollection routes)

                new { controller = "Home", action = "post" }

                new { controller = "Home", action = "Index", id = "" }




Just added here a dbml file (Linq to Sql DataContext) , and I added a PostEx.cs file and added a property for the Post, God Bless partial classes. PostEx.cs as shown in Listing 2.


public partial class Post
        public string RelativeLink
                return VirtualPathUtility.ToAbsolute("~/post/") + Slug;



For now I only have one controller the HomeController which has simply 3 actions for now.

  • index : Renders a view with all posts sorted in a chronological order
  • post(slug) : Renders a view for the post with a matching slug if not found it renders error404 view
  • premalink(guid) : Renders a view for the post with a matching guid if not found it renders error404 view

HomeController as shown in Listing 2.


public class HomeController : Controller
        /// <summary>
        /// Renders a view with all posts sorted in a chronological order
        /// </summary>
        /// <returns></returns>
        public ActionResult index()
            var posts = Helpers.GetPostList() ?? new List<Post>();
            return View(posts);

        /// <summary>
        /// Renders a view for the post with a matching slug
        /// if not found it renders error404 view
        /// </summary>
        /// <param name="slug">Post slug to be matched</param>
        public ActionResult post(string slug)
            var post = Helpers.GetPostBySlug(slug);
            return post != null ? View("single", post) : View("error404");

        /// <summary>
        /// Renders a view for the post with a matching premalink
        /// if not found it renders error404 view
        /// </summary>
        /// <param name="id">Post premalink to be matched</param>
        public ActionResult premalink(Guid id)
            var post = Helpers.GetPostByPemalink(id);
            return post != null ? View("single", post) : View("error404");



The solution now contains one master page for the overall site, three views, and one usercontrol

  • site.Master : gives the overall look and feel for the site
  • index.aspx : renders all posts.
  • single.aspx : renders a single post.
  • error404.aspx : to be rendered when a request to a non matching post slug or premalink
  • _postView.ascx : the post template to be used


Two classes that help me

  • Config: Contains some static properties that read from hard coded strings (in a version coming up should read from the web.config or even a database table).
  • Helpers: just some common helper methods.

Config File


public class Config
       static public string BlogName { get { return "My Blog Name"; } }
       static public string BlogDescription { get { return "This blog is built using the ASP.NET MVC framework."; } }
       static public string BlogUrl { get { return VirtualPathUtility.ToAbsolute("~/"); } }
       static public string Version { get { return ""; } }





In this part, I just announced jBlogMvc the ASP.NET MVC and jQuery blogengine which I build in order to learn more about the two new technologies (at least for me), so what do you think? you are most welcomed to leave comments.

Download version zero : (624.80 kb)

If you liked this blog post then please subscribe to this blog.

SP Dev part 2 : Understanding Sharepoint Custom Pages

NOTE: If you haven't read the first post in this series, I would encourage you do to that first, or check out the Sharepoint category. You can also always subscribe to the feeds.

The Sharepoint 2007 System introduces two types of pages the first type usually called Application Pages and other type called Site Pages.

As a sharepoint developer you should know both of these types of pages and when to use them, so let me define them here briefly and show some differences between them to help you decide which type of pages you will want to use when developing in sharepoint.

Application Pages

Application Pages are non customizable and are found in  the C:Program FilesCommon FilesMicrosoft Sharedweb server extensions12TEMPLATELAYOUTS, its worthy to note that this physical directory is mapped to the virtual _layouts directory whenever WSS/MOSS creates a new Web application in the IIS. By using this mapping scheme along with some additional processing logic, the WSS/MOSS runtime can make each application page accessible within the context of any site in the farm.

When building custom application pages you should use the Microsoft.Sharepoint.LayoutsPageBase as a base class and should be content pages that reference to the ~/_layouts/application.master master page, Application Pages might include in line code or have a code behind file compiled in a dll, to deploy application pages they should be the LAYOUTS directory and all custom code dlls either in the GAC.[more]

Standard Application Pages in the WSS

Site Pages (Content Pages)

Site Pages can be customized on a site-by-site basis. default.aspx page in the Blank site is considered a site page as well as the AllItems.aspx used in lists. When customizing site pages this might lead to hundreds of versions of one site pages, site pages have only one physical version and all customized pages reside in the Content Database of the Web Application. This leads us to one important optimization point known as page ghosting, imagine that you have just created 100 new WSS sites from the Blank Site template. If none of these sites requires a customized version of its home page (default.aspx), would it still make sense to copy the exact same page definition file into the content database 100 times? Ofcourse not, rather than copying 100 version of the same page in the content database, the WSS runtime can load the page template from the file system of the Web server and use it to process any request for an uncustomized page instance. Therefore, you can say that page ghosting describes the act of processing a request for an uncustomized page instance by using a page template loaded into memory from the file system of the front-end Web server.

Security consideration : Since the site page can be customized for every customized version, a copy must be stored in the content database, which in turn raises a security issue what if a user having an administrator permission and tries to write in line code within a customized version. This security concern is dealt in WSS by having a default policy that prohibits in line scripting in site pages. The default policy also runs site pages in a no-compile mode, which means they are not compiled into DLLs.



In this part I just scratched the 2 types of pages used in the Sharepoint System I have to say that there is more and more to talk about on this topic which I will write more through this series.

SP Dev part 1 : Sharepoint 2007 Development model {Features}

Sharepoint A new feature in the Sharepoint 2007 is the "Feature" development style which means that every tiny and huge development task in the sharepoint is considered a "Feature".

Features can be activated or deactivated through a site administrator, which enables the very simple turn on/off of anything in the site.

Features are used for developing anything starting from a small button to a full site definition and tons of files and functions including webparts, workflows, lists, pages, content types, document libraries and others. I will try to include the development of all these topics in this series wish me luck and provide feedback. [more]

For a start I will show here in this part how to get started with the feature development and the basic elements and files needed for a developing and deploying a sharepoint feature.

Before opening the Visual Studio and starting to code, knowing what the files and where will they be deployed on the server will be mandatory. A very basic feature will include 2 xml files one named feature.xml and the other will hold the elements of this feature usually named elements.xml or elementsManifest.xml, consider that the files for any feature must be deployed in their own special directory inside the WSS system directory named FEATURES. The FEATURES directory is located inside another WSS system directory named TEMPLATE.

C:Program FilesCommon FilesMicrosoft Sharedweb server extensions12TEMPLATEFEATURES

In our Hello sharepoint feature we will make a very basic feature named HelloSharepoint that when activated will add menu item in the SiteActions menu that will redirect to google.


Title="Hello Sharepoint Feature"
Description="This is a custom feature which adds a custom item to link to google"
<ElementManifest Location="ElementsManifest.xml" />

As shown above the feature.xml looks very simple, only Id and Scope are the two required attributes and all the others are optional and a full list can be found here.


<Elements xmlns="">
Title="Hello Sharepoint"
Description="A custom menu item links to google"
ImageUrl="_layouts/images/google.gif" >
<UrlAction Url=""/>

And the elementsManifest.xml here describes the elements to be installed with the feature and we only define one element (a CustomAction) you find a bunch of types of elements to be added here.

That's all we are done with building our very first feature inside the WSS/MOSS world, I know some of the attributes here seem vague and other seem simple anyway I will try to put a part or two for only discussing these files with their various options.


Deploying the feature


  1. Copying the feature files (feature.xml and elementsManifest.xml) in the Features server path
    C:Program FilesCommon FilesMicrosoft Sharedweb server extensions12TEMPLATEFEATURES , and the google.gif in the C:Program FilesCommon FilesMicrosoft Sharedweb server extensions12TEMPLATELAYOUTSimages
  2. Running STSADM.EXE operation to install the feature with WSS/MOSS "stsadm -o InstallFeature -filename HelloSharepointfeature.xml -force"
  3. Restarting IIS
  4. Finally, activating the features within the site administration (6.74 kb)

Upgraded to BlogEngine 1.4.5

Finally working with fully featured BlogEngine on godaddy the BlogEngine v 1.4.5 has been released and I had the time to update my blog, and finally works as a charm with godaddy shared hosting.

Some features that didn't work with the 1.4 version was the whole new widget system, Profiles and anything that used the BinaryFormatter at the end, which needed a high or full trust while godaddy shared hosting only allows meduim trust.

In version 1.4.5 Mads and the team removed all the BinaryFormatters references and used normal xml serializers save the widget and extension settings.

For all blogengine users using shared hosting, go ahead v 1.4.5 works out of the box, and also check the new features released in the latest version.

Beginning Sharepoint 2007 Development

I mentioned a long while ago that I will work on some sharepoint and workflow foundation in order to enlarge my development knowledge base, I learned some stuff on the way may be all sharepoint and workflows beginners already know them but I love to share them for others.

I will start another series for sharepoint development (for beginners as myself) so If anyone out there finds out a better approach for anything I write or correction welcome for commenting on the posts so all can benefit too.

This series will start with introductory posts that are needed to understand the architecture and object model of sharepoint, these introduction points are all over the web and blogs of sharepoint pros, I will write them again in my wa, then proceed with some basic development then advanced, I don't have an outline for the posts I am gonna write I have some ideas any reader is welcome to add in comments any topic related to sharepoint development wants me to write about, hoping this series be useful like my older one Design Time Support of Custom Controls, so wish me luck.


Have been tagged

This blog has been idle for some while, I was very busy, out of mood, studying for my masters and reading new technologies (for me like workflow and sharepoint development and some WCF). I didn't know what time my blogging mood will be back, until my friend Moses insisted to get me back and tagged me in the how I got started in software development, that started a while ago by Michel Eaton. So here we go.

How old were you when you started programming?

10 years old (12 years ago).

How did you get started in programming?

My father used to make simple programs using C that showed dots and stuff I dont get till now Smile, he used to let me write for him some code. Few years more my sister joined computer science and had assignments to program C++ application thats when I really got involved and started to read.(16 years old)

What was your first language?

By that time it was C. 

What was the first real program you wrote? 

My very first own program I wrote was the famous star pyramid using C++, My first windows application and favourite is the MineSweeper, which is my helloworld application that I used for many languages, I used to have the following minesweeper versions (WinForms, WPF, Assembly, Silverlight, OpenGL, DirectX, javascript).

What languages have you used since you started programming?

C, C++, VisualBasic.Net, C#, Java, Assembly, Prolog, Javascript, HTML/XHTML, XAML and lot of other technologies related to development not considered programming language.

What was your first professional programming gig?

Was 4 years ago, I used C# for building winforms applications connecting to databases in my summer training that time.

If you knew then what you know now, would you have started programming? 

OfCourse. I code with passion, love blogging and exploring new technologies around the block. I could have never imagined myself anything other than what am I in now.

What is the one thing you would tell new developers?

Code for fun not for money. Have a life. Don't forget to lie to girls &  Buy your RayBan as Mads said I already got mineCool thank you Mads.

What's the most fun you've ever had … programming?

Building my very first Minesweeper and talking about it to my very best friend that time.

Now what ..?

First, I'd like to thank my friend Moses for not only tagging me but for making me get back to the blogging mood, I hope to continue blogging regularly like old days.

Second, I'd like to pass this to my favourite bloggers, most of them already have been tagged, I recommend you reading them too, Dave, Matt, Mads, Moses, Joe and Keyvan. And now I tag Bashmohandes to write his story.

Anyone reading this and wants to write about his story just head straight to Michel's post and write him a comment.

Moving to Sharepoint and Workflow

My blog has been quiet for a long time now, I had a crowded month I didn't get the time to write anything but I am back to writing I hope so.

Last month I had some working tasks on new technologies (for me) , a new course to study for and of course all my PreMasters studies in my university.

So, I think my focus next blog post will be on the new stuff I learned about Sharepoint 2007 and workflow foundation hope I can write something useful.

By the way I have just passed the 70-631 Exam TS: Configuring Windows SharePoint Services 3.0. So I have a new MCTS in my transcript.

Yet another BlogEngine.NET feature that I love

A while ago, Al Nyveldt wrote a post on 5 things he loves about BlogEngine.Net  and I totally agree with him on all the 5 and more coming in the future releases,  Mads Kristensen too wrote and made a video on a the widget framework on a nice feature coming up in the next version of

BlogEngine.Net is built to take advantage of standards, one standard I loved that is implemented in BlogEngine is the OpenSearch 

The cool thing about this standard is that modern browsers are able to detect it and have the option to add the search through the blog.

Internet explorer 7  firefox 2

The opensearch standard is an xml document written in a special format you can see mine here.

And when I search through the browser I am sent to this :


So to implement opensearch in your site, (should have something to search in) you need to do these 2 steps.

  1. Build an opensearch format xml file.
  2. Attach the file from your homepage using the appropriate tag in the head section, like the following.
<link title="Amr Elsehemy's Weblog" type="application/opensearchdescription+xml" 
href="http://www.amrelsehemy/opensearch.axd" rel="search"/>

Thats All.

ASP.NET Security : 2- More Basics

In my previous post I showed that ASP.NET application goes through 3 security context levels and discussed the first one :

  1. IIS Level
  2. ASP.NET worker process level
  3. ASP.NET pipeline level

In this post, I will talk a little on ASP.NET worker process level, before starting I would like to point out the development environment we use, the development machines run windows XP and IIS 5.1, the server runs windows server 2003 on IIS 6 of course, so I need to point out the differences. [more]

2- The Worker Process Context :


After IIS authentication, if the request is for ASP.NET (.aspx, .ashx, ….etc. ) the IIS thread sends the request to aspnet_isapi.dll which starts the aspnet_wp worker process. This worker process runs under the ASPNET account. ASPNET account is a local account created when the .NET Framework is installed. ASPNET has minimum privileges to be able to run an ASP.NET application which you can know in this article :
You can change the identity from ASPNET to other one using the section in machine.config

	<processModel userName="xxx" password="XXX"/>

In IIS 6, the model is changed where the incoming request in first queued to the application pool that the website is hosted in, then the w3wp.exe worker process servers it.
This time rather than the ASPNET account a new one was introduced named NETWORK SERVICE with the same minimum privileges. To change the this account from the IIS manager, the Application Pool properties > Identity Tab as shown in figure, Read More on Application Pools.

iis pool identity

Next in the worker process, one of the pooled threads picks the request. This thread will by default inherit the identity of the worker process itself defined before, this happens when impersonation is disabled, while if it is enabled the thread will take the identity handed by the IIS, shown in the previous post.

To enable impersonation use this section in web.config

<identity impersonate="true"/>

read more about it on How to implement impersonation in an ASP.NET application

Note: If the impersonation is enabled, the worker process account doesn't change, but impersonation is only used with the code executed in the page, where any database access or file access uses the impersonated account.

Next the last security context level is handled the request and executes, next post I will show preliminary information on the ASP.NET pipeline level.

ASP.NET Security : 1- Basics

Lately at SCS I have been assigned to build up the security module and related tasks in the Real Estate Management System we are building. So I decided to share what I have learned in this past period and of course to hear from the community to find optimal solutions for the scenarios I worked with, all what I write here might be repeated but I will share it anyway. [more]

In this part, I will show some important basic points that should be clear to everyone before implementing security tasks.

Looking at any web application, the security is a matter of users/passwords/roles/groups… etc. While ASP.NET provides more mechanisms for authentication and authorization that work with the Operating system,IIS and .NET framework classes. So the ASP.NET application runs through these 3 levels.

  • IIS Level
  • ASP.NET worker process level
  • ASP.NET pipeline level

So, the Big Question, What is the Identity that runs my application ?

First, When an IIS web server machine receives an ASP.NET request, the IIS assigns it to one of the threads pooled in it, IIS runs under the SYSTEM account which has all the powers in a Microsoft Windows operating system. You can read extra information in the ASP.NET Application Life Cycle Overview article on the msdn.

Next, the 3 security levels run on the request one after the other.

1- The IIS thread context : the identity of this thread is determined according to the settings of the website in the IIS which has one of the following settings:

  1. Basic authentication prompts the user for a user name and a password, also called credentials, which are sent unencrypted over the network.
  2. Integrated Windows authentication uses hashing technology to scramble user names and password before sending them over the network.
  3. Digest authentication operates much like Basic authentication, except that passwords are sent across the network as a hash value. Digest authentication is only available on domains with domain controllers running Windows Server operating systems.
  4. Anonymous authentication allows everyone access to the public areas of the Web sites, without asking for a user name or password. When this is set, the identity impersonates the identity set in the textboxes, with the default user name IUSR_MACHINENAME. Like shown in the figure down below.

Further more, IIS provides SSL (Secure Socket Layer) authentication mode that is based on certificates, to authenticate users requesting/providing secret information on the server, two trusted certificate providers (which I know but never used) are and

AuthenticationMethods IIS 5

After authentication, the thread sends the request to the appropriate external module.

Next part I will talk about the 2 next security level contexts.