<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title type="html">Mr. Roa</title>
  <icon>http://mrroa.com/Content/icons/mushroom.ico</icon>
  <logo>http://mrroa.com/Content/icons/mushroom.png</logo>
  <updated>2010-02-28T05:44:00</updated>
  <subtitle type="html">The name is Roa. Mr. Roa</subtitle>
  <id>http://mrroa.com/atom</id>
  <link rel="alternate" type="text/html" hreflang="en" href="/atom"/>
  <link rel="self" type="application/atom+xml" href="http://mrroa.com/ATOM"/>
  <generator uri="http://oxite.net" version="1.0">Oxite</generator>
  <entry>
    <title type="html">How to use Membership/Role Provider and when to use custom implementations</title>
    <link rel="alternate" type="text/html" href="http://mrroa.com/Blog/How-to-use-MembershipRole-Provider-and-when-to-use-custom-implementations"/>
    <id>http://mrroa.com/Blog/How-to-use-MembershipRole-Provider-and-when-to-use-custom-implementations</id>
    <updated>2010-03-10T01:37:41.463</updated>
    <published>2010-02-28T05:44:00</published>
    <author>
      <name>Admin</name>
    </author>
    <category term="providermodel" />
    <category term="membership" />
    <category term="role" />
    <content type="html" xml:lang="en">
      &lt;p&gt;Authentication is a must have feature for every system. Every system administrator needs to give an identity to the ones using their system. Which leads us, developers, to make this repetitive process something easier to implement and reuse every now and then on any application that may need user login.&lt;/p&gt;
&lt;p&gt;I've seen many &quot;authentication frameworks&quot; which encapsulate simple verification routines into assemblies, that can be implemented as easy as just creating a reference and running a sql script against the DB. What the heck! Even I made one of those and felt 1337 because of my glorious creation. But! That was until I meet the &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/ms972319.aspx&quot; target=&quot;_blank&quot;&gt;provider model&lt;/a&gt;, which reduced the greatness of my crappy &quot;framework&quot; or I may say, reinvention of the wheel.&lt;/p&gt;
&lt;p&gt;The provider model involves many other things that go a lot further than just user authentication, resource permissions, etc. For now I'll address the ones related to user management and their default implementation.&lt;/p&gt;
&lt;h3&gt;What? More sh*!t about&amp;nbsp;Membership/Role/Profile Provider?!! Why should I care?&lt;/h3&gt;
&lt;p&gt;Let's start by saying that this is not something new. The provider model has been around since ASP .NET 2.0, therefore 5 years ago you could've done this without any problem the same way I'm gonna do it now. The deal is that people rather read or download an example from a blog, than actually spend some time reading about how the thing works and what's the most suitable way of implementing it
&lt;script src=&quot;../../../Skins/Default/Scripts/tiny_mce/themes/advanced/langs/en.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
depending t
&lt;script src=&quot;../../../Skins/Default/Scripts/tiny_mce/themes/advanced/langs/en.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
heir given situation.&lt;/p&gt;
&lt;p&gt;Instead of trying to write a manual of how to do it, I'll try to explain why use the default or simplest form of the provider model for user management rather than opting for a custom membership provider. Of course if you are able to choose how to handle your users and you don't stick an existing form of user authentication into your app. Either way I encourage you to drop your &lt;a href=&quot;http://en.wikipedia.org/wiki/Leet&quot; target=&quot;_blank&quot;&gt;1337&lt;/a&gt; implementation, and use this since the Login controls work out of the box.&lt;/p&gt;
&lt;p&gt;My intention is to eradicate the taboo surrounding t
&lt;script src=&quot;../../../Skins/Default/Scripts/tiny_mce/themes/advanced/langs/en.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
his, and really show how simple it is to make this work along with our application without any effort at all.&lt;/p&gt;
&lt;h3&gt;To Customize the provider or not to customize the provider&lt;/h3&gt;
&lt;p&gt;So, in order to make the provider a viable solution they had to make it flexible. And it is. By simply extending the membership, role or provider base classes you can implement your own customization of these providers. The thing is that people tend to opt for this without hesitating falling again into the loop of reinventing something that it's already done for you.&lt;/p&gt;
&lt;p&gt;Everything resumes to this: Unless you have to use a pre-defined structure for the users database your option will be a custom implementation of the membership/role/profile providers. But if you are using ASP .NET 2.0 or higher (obviously), MSSQL, and do not have to use an existing user base you shouldn't create your custom provider.&amp;nbsp;There are also ports of the ASP .NET Application Services DB for Oracle, MySQL and Postgre, so there are not excuses for this.&lt;/p&gt;
&lt;p&gt;The usual excuse for resistance of using the default implementation of the provider is the&amp;nbsp;assumption&amp;nbsp;of &quot;having to rely on the username field and having alphanumeric fields as FK's among the whole system might affect performance&quot;. This, even though it sounds technically convincing it's a lie. All the relationships on the default DB schema are made using GUID's which definitely knock off this vague excuse. Obtaining the user's unique identifier takes as little as two lines of code, so don't let that stop you.&lt;/p&gt;
&lt;p&gt;Avoiding the implementation of a custom membership/role/profile provider WILL save you time and let you focus on other tasks more important than user administration and resource permissions.&lt;/p&gt;
&lt;h3&gt;OK, so where's the code?&lt;/h3&gt;
&lt;p&gt;Since I'm not addressing a custom implementation of any of the providers being discussed. It's only going to be necessary to configure the providers using the web.config or the ASP .NET Configuration panel. There are a couple of ways of implementing the membership and role provider on its simplest form. One way is to use the ASP .NET Configuration in order to achieve it. Let's see how.&lt;/p&gt;
&lt;h4&gt;Step 1&lt;/h4&gt;
&lt;p&gt;First, select the ASP .NET Configuration option from your Website menu in Visual Studio.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;http://s.mrroa.com/membershipstep1a.png&quot; alt=&quot;ASP .NET Configuration&quot; width=&quot;700&quot; height=&quot;460&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Note that this will open a website which contains the website configuration settings grouped in three categories: Security, Application Configuration &amp;amp; Provider Configuration.These presented options on the ASP .NET Configuration website will allow us to configurate everything, from authentication methods, users and all that other stuff to smtp mail servers (of course this is useful if our application sends emails, for instance a user password reset). Here's what you can do on each tab:&lt;/p&gt;
&lt;p&gt;Security.- Here you'll be able to find the user/role configuration stuff, you'll be able to do CRUD operations on your users and roles, and also define the access rules per user/role for your application resources.&lt;/p&gt;
&lt;p&gt;Application Configuration.- Here, you can define application settings which are just application are keys that are going to be accessible from the &amp;lt;appSettings/&amp;gt; dictionary. Also you'll be able to set the stmp settings, take the application offline and set the debugging and tracing options.&lt;/p&gt;
&lt;p&gt;Provider Configuration.- Here, you can select the providers you'll on the application, these is very useful since you can define various providers on your web.config (if you'd like) and switch through them. For instance the settings for your application on the development environment are different from your production environment.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;http://s.mrroa.com/membershipstep1b.png&quot; alt=&quot;ASP .NET Configuration&quot; width=&quot;700&quot; height=&quot;460&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Also, this action will automatically create a new Database file and place it on your App_Data folder of your website/webapp. This database named aspnetdb will contain the Application Services DB schema definition.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;http://s.mrroa.com/membershipdb.png&quot; alt=&quot;ASP .NET Application Services DB&quot; width=&quot;700&quot; height=&quot;460&quot; /&gt;&lt;/p&gt;
&lt;h4&gt;Step 2&lt;/h4&gt;
&lt;p&gt;You just need to access the Security tab and start creating your users, roles and access rules.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;http://s.mrroa.com/membershipstep2.png&quot; alt=&quot;ASP .NET Application Services DB&quot; width=&quot;700&quot; height=&quot;460&quot; /&gt;&lt;/p&gt;
&lt;p&gt;By default we have in our hands a simple yet robust implementation of user management. We are able to select the forms of authentication for our application from the provided configuration options, Windows or Forms, these options are described on the &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/ff359131.aspx&quot; target=&quot;_blank&quot;&gt;msdn documentation&lt;/a&gt;. When using forms authentication, the passwords of our users are going  to stored on our database, by default these are going to be hashed.  Also our users need to have a secret question/answer in order to  reset/retrieve their passwords.&lt;/p&gt;
&lt;p&gt;From our application will be able  to access all of these user  management CRUD actions by using the  System.Security.Membership class.  All of the Login Toolbox controls  located on the visual studio Toolboox  palette, will work without  writting a single line of code.&lt;/p&gt;
&lt;h3&gt;Great! But what if I want to use my own Database&lt;/h3&gt;
&lt;p&gt;So you already have designed your application database and you want  include the Application Services Schema definition in it. This is a very  common scenario, and you'll need to do very little to get this working.&lt;/p&gt;
&lt;p&gt;First, you need to run the &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/x28wfk74.aspx&quot; target=&quot;_blank&quot;&gt;aspnet_regsql&lt;/a&gt; command from the visual studio command prompt and go through the, fairly simple, wizard  until you select and register your database. This will copy all the Application Services tables and store procedures that you'll need to use the Provider Model into your existing DB.&lt;/p&gt;
&lt;p&gt;After that, you'll need to define a connection string that points to that database on your web.config. This connection string will be specified on our membership provider definition.&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&amp;lt;remove name=&quot;LocalSqlServer&quot;/&amp;gt;
&amp;lt;add name=&quot;LocalSqlServer&quot; connectionString=&quot;Data Source=.\SQLEXPRESS;Initial Catalog=MyAppDB;Persist Security Info=True;&lt;br /&gt;User=sa;Password=P@$$w0rd&quot; providerName=&quot;System.Data.SqlClient&quot;/&amp;gt;&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Now we just need to define the provider and then change the membership provider for the application to use our new one on the Provider Configuration.&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&amp;lt;system.web&amp;gt;  
   &amp;lt;membership userIsOnlineTimeWindow=&quot;20&quot; hashAlgorithmType=&quot;SHA1&quot;&amp;gt;
      &amp;lt;providers&amp;gt;
        &amp;lt;add connectionStringName=&quot;LocalSqlServer&quot; enablePasswordRetrieval=&quot;false&quot;
          enablePasswordReset=&quot;true&quot; requiresQuestionAndAnswer=&quot;false&quot;
          passwordFormat=&quot;Hashed&quot; applicationName=&quot;MyApplication&quot; name=&quot;MyAppMembershipProvider&quot;
          type=&quot;System.Web.Security.SqlMembershipProvider&quot; /&amp;gt;
      &amp;lt;/providers&amp;gt;
   &amp;lt;/membership&amp;gt;
&amp;lt;/system.web&amp;gt;
&lt;/pre&gt;
&lt;h3&gt;Retrieving the User Unique Identifier&lt;/h3&gt;
&lt;p&gt;If you need to create a relationship between a user and any other entity by using it's unique identifier (GUID) instead of its username, you just need to retrieve it by using the read-only property ProviderUserKey from the MembershipUser class.&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;System.Web.Security.MembershipUser&amp;nbsp;mu = System.Web.Security.Membership.GetUser();&lt;br /&gt;string&amp;nbsp;usrID = mu.ProviderUserKey.ToString();&lt;/pre&gt;
&lt;h3&gt;Conclusion&lt;/h3&gt;
&lt;p&gt;On this blog post, I discussed ASP .NET Membership &amp;amp; Role provider  implementations on it's simplest form, which in my opinion should be your  first option when implementing this feature, of course if the scenario allows  it. Custom implementation of the providers aren't bad and I'm not  against them but you should use them when its necessary, that's all. This topic was very debated when this feature first came out, and &lt;a href=&quot;http://www.4guysfromrolla.com/articles/120705-1.aspx&quot; target=&quot;_blank&quot;&gt;4 Guys from  Rolla&lt;/a&gt; have a very good series of articles that go in depth on the  subject, I encourage you to read it if you are interested on learning  how this thing works.&lt;/p&gt;
    </content>
  </entry>
  <entry>
    <title type="html">Oxite: Blog Description &amp; Profile Management</title>
    <link rel="alternate" type="text/html" href="http://mrroa.com/Blog/Oxite-Blog-Description--Profile-Management"/>
    <id>http://mrroa.com/Blog/Oxite-Blog-Description--Profile-Management</id>
    <updated>2010-01-15T12:39:06.38</updated>
    <published>2010-01-10T09:33:00</published>
    <author>
      <name>Admin</name>
    </author>
    <category term="profile" />
    <category term="Oxite" />
    <category term="slogan" />
    <content type="html" xml:lang="en">
      &lt;p&gt;Following my Oxite blog post series, I add some extra functionality to the administration panel of the blog engine as well as some little changes to the blog engine title, shown on the front-end. Also I'll use this oportunity to give a little insight about Oxite's core and internal structure.&lt;/p&gt;
&lt;h3&gt;Let's vent first...&lt;/h3&gt;
&lt;p&gt;If you search and read reviews you may notice that Oxite it's not considered to be good at all. Actually is not referred as a Microsoft ASP .NET MVC Framework guidance project, not even a starter kit. Adding to that I'm absolutely sure when I say it's not even close to a &quot;Best Practices &amp;amp; Patterns&quot; repository for ASP .NET MVC Framework enthusiasts.&lt;/p&gt;
&lt;p&gt;Instead of wasting time reinventing the wheel, by reviewing the code (again!) or the project as a whole. I'll just summarize what I think of it with a single sentence. Ready? Here it goes. Oxite is an unorthodox, undocumented and untested application made with good intentions. MVC is supposed to enforce the developer to come up with a good application design, but ironically this just makes Oxite a good anti-pattern example providing a high coupled/low cohesive design and incredible complex project structure due to unnecessary&amp;nbsp;abstraction layers. Perhaps it's just because it's not a finished product and it was created in the early stages of a maturing technology. Who knows?!&lt;/p&gt;
&lt;p&gt;I'll admit I like the challenge and that's precisely why I chose this as my starting point for my blog engine. I know the guys who created this have a disclaimer, telling me other &quot;mature&quot; choices, BUT I didn't expect to be abbandoned in this creepy box of moving sand! (Look for Orchard in codeplex).&lt;/p&gt;
&lt;h3&gt;And now... The features&lt;/h3&gt;
&lt;p&gt;So, if you follow other bloggers you may have noticed that they all have a funky/catchy phrase below the blog title. And if you watch closely, you may notice that the funky/catchy phrase is missing here. You may be thinking, so what? it's no biggie. And you might be right. But in the end, advertisement, which should be considered a science, proves you wrong! These phrases have a name! They are called slogans, and they have claimed to be the most effective means of drawing attention (according to &lt;a href=&quot;http://en.wikipedia.org/wiki/Advertising_slogans&quot; target=&quot;_blank&quot;&gt;wikipedia&lt;/a&gt;). But the most interesting thing is that a slogan implies&amp;nbsp;distinction between products, and that's it! that's what we must always pursue when having a web page among millions and millions... DISTINCTION!&lt;/p&gt;
&lt;p&gt;Jumping right into business, achieving this is fairly simple. The Site entity has a property called Description, which is accessible from the Model in the view. This is convenient since we are able to update the description already from the settings tab in the Admin section.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;http://s.mrroa.com/editsite.PNG&quot; alt=&quot;Edit Site&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Then locate the header.ascx on your skin folder. Change the title div as follows:&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&amp;lt;div id=&quot;title&quot;&amp;gt;
    &amp;lt;h1&amp;gt;&amp;lt;a href=&quot;&amp;lt;%=Url.Posts() %&amp;gt;&quot;&amp;gt;&amp;lt;%=Model.Site.DisplayName %&amp;gt;&amp;lt;/a&amp;gt;&amp;lt;/h1&amp;gt;
    &amp;lt;%=Model.Site.Description %&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;So that's it, nice and simple! Now we have a fancy catch phrase space. Which reminds me, now I need a slogan!&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;http://s.mrroa.com/title.PNG&quot; alt=&quot;title&quot; /&gt;&lt;/p&gt;
&lt;p&gt;The next thing is something that really annoyed me. While browsing through the issues on &lt;a href=&quot;http://www.codeplex.com/oxite&quot; target=&quot;_blank&quot;&gt;oxite's codeplex page&lt;/a&gt;, I learned that in order to change the logged user's display name (in this case the admin, since oxite does not support user management yet ;) you had to go to the database and change it manually. I can't stand the greeting message when I log in, every time I read &quot;Welcome, Oxite Administrator!&quot; I get cranky and bored. So let's fix that and put our name there!&lt;/p&gt;
&lt;p&gt;First we need to locate the routes dictionary class. It's a class file called OxiteRoutes.cs located on the Oxite project. This is how our new route looks.&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;AddRoute(
      &quot;UserChangeProfile&quot;,
      &quot;Admin/ChangeProfile&quot;,
       new { controller = &quot;User&quot;, action = &quot;ChangeProfile&quot;, validateAntiForgeryToken = true },
       null,
       new { Namespaces = controllerNamespaces });
&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Cool, so let's take a look to what we did here. We defined a route name: &quot;UserChangeProfile&quot; and mapped an url to it: &quot;Admin/ChangeProfile&quot;, according to our routing engine this url must be mapped to an action, which we defined on the object defaults attribute. We said that the action will be: &quot;ChangeProfile&quot; and that it's going to be located on the UserController.cs. The other parameters are tokens and other optional properties.&lt;/p&gt;
&lt;p&gt;Oxite also has a Helper class for url generations from the views. It's called UrlHelperExtensions.cs and it's located on the Oxite.Mvc project inside of the Extensions folder. We should add this snippet there.&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;public static string UserChangeProfile(this UrlHelper urlHelper)
{
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return urlHelper.RouteUrl(&quot;UserChangeProfile&quot;);
}&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;So now that we are done with the routing, we need to change the EditUser method on the service that is going to be used by the controller. I just modified the signature of the EditUser method interface to look like this:&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;void EditUser(User user, bool passwordUpdate, out ValidationStateDictionary validationState);&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I added a small modification to the method implementation, so we don't modify the user password when change the user full name. The implementation looks like this:&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;public void EditUser(User user, bool passwordUpdate, out ValidationStateDictionary validationState)
{
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;validationState = new ValidationStateDictionary();
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;validationState.Add(typeof(User), validator.Validate(user));

&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;if (!validationState.IsValid)
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;{
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;}

&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;if (!string.IsNullOrEmpty(user.Password) &amp;amp;&amp;amp; passwordUpdate)
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;{
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;user.PasswordSalt = Guid.NewGuid().ToString(&quot;N&quot;);
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;user.Password = saltAndHash(user.Password, user.PasswordSalt);
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;}

&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;user.HashedEmail = user.Email.ComputeHash();
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;repository.Save(user);
}&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Ok, so we only need to do two more things and we are done. First we need to add the controller action definition that is going to be called by the routing engine, and second we need to create the view that is going to be rendered by this action.&lt;/p&gt;
&lt;p&gt;First let's edit the UserController. Let's add our actions for HTTP verbs Get/Post.&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;[ActionName(&quot;ChangeProfile&quot;), AcceptVerbs(HttpVerbs.Post)]
public virtual object ChangeProfileSave(User currentUser, FormCollection form)
{
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;string name = form[&quot;displayName&quot;];
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;string email = form[&quot;email&quot;];
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ValidationStateDictionary validationState;

&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if (string.IsNullOrEmpty(name))
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ModelState.AddModelError(&quot;displayName&quot;, &quot;New Name is not set.&quot;);
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}

&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if (string.IsNullOrEmpty(email))
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ModelState.AddModelError(&quot;email&quot;, &quot;New Email is not set.&quot;);
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}

&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if (ModelState.IsValid)
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;currentUser.DisplayName = name;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;currentUser.Email = email;

&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;userService.EditUser(currentUser, false, out validationState);

&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if (!validationState.IsValid)
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ModelState.AddModelErrors(validationState);
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}

&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if (!ModelState.IsValid)
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ModelState.SetModelValue(&quot;displayName&quot;, new ValueProviderResult(name, name, CultureInfo.CurrentCulture));
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ModelState.SetModelValue(&quot;email&quot;, new ValueProviderResult(email, email, CultureInfo.CurrentCulture));

&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return ChangeProfile(currentUser);
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return Redirect(Url.AppPath(Url.ManageUsers()));
}&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Finally, let's add our view code.&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&amp;lt;%@ Page Language=&quot;C#&quot; AutoEventWireup=&quot;true&quot; 
&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;MasterPageFile=&quot;~/Views/Shared/Admin.master&quot; Inherits=&quot;System.Web.Mvc.ViewPage&amp;gt;&quot; %&amp;gt;
&amp;lt;%@ Import Namespace=&quot;Oxite.Mvc.Extensions&quot; %&amp;gt;
&amp;lt;asp:Content ContentPlaceHolderID=&quot;MainContent&quot; runat=&quot;server&quot;&amp;gt;
    &amp;lt;h2 class=&quot;title&quot;&amp;gt;&amp;lt;%=Model.Localize(&quot;ChangeProfile&quot;, &quot;Change Profile&quot;) %&amp;gt;&amp;lt;/h2&amp;gt;
    &amp;lt;%=Html.ValidationSummary() %&amp;gt;
    &amp;lt;form action=&quot;&quot; method=&quot;post&quot;&amp;gt;
    &amp;lt;div&amp;gt;
        &amp;lt;%=Html.TextBox(&quot;displayName&quot;,  m =&amp;gt; m.User != null ? m.User.DisplayName : &quot;&quot;,&amp;nbsp;
                            Model.Localize(&quot;DisplayName&quot;, &quot;Display Name&quot;), new { size = 42, @class = &quot;text&quot; })%&amp;gt;
    &amp;lt;/div&amp;gt;
    &amp;lt;div&amp;gt;
         &amp;lt;%=Html.TextBox(&quot;email&quot;,  m =&amp;gt; m.User != null ? m.User.Email : &quot;&quot;,
                             Model.Localize(&quot;Email&quot;, &quot;Email&quot;), new { size = 42, @class = &quot;text&quot; })%&amp;gt;
     &amp;lt;/div&amp;gt;
     &amp;lt;div&amp;gt;
         &amp;lt;input type=&quot;submit&quot; name=&quot;submit&quot; class=&quot;submit button&quot;
&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;  &lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; value=&quot;&amp;lt;%=Model.Localize(&quot;ChangeProfile&quot;, &quot;Change Profile&quot;) %&amp;gt;&quot; /&amp;gt;
         &amp;lt;%=Html.OxiteAntiForgeryToken(m =&amp;gt; m.AntiForgeryToken) %&amp;gt;
     &amp;lt;/div&amp;gt;
     &amp;lt;/form&amp;gt;
 &amp;lt;/asp:Content&amp;gt;
 &amp;lt;asp:Content ContentPlaceHolderID=&quot;Scripts&quot; runat=&quot;server&quot;&amp;gt;
     &amp;lt;% Html.RenderScriptTag(&quot;site.js&quot;); %&amp;gt;
 &amp;lt;/asp:Content&amp;gt;&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;That's it ladies and gentleman! Now we are able to modify our user's email and display name.&lt;/p&gt;
&lt;h3&gt;UPDATE!&lt;/h3&gt;
&lt;p&gt;After making these changes, I noticed that something else had to be done to get a complete solution to the DisplayName fix. After applying the updates above we successfully update the DisplayName to whatever we want, but Admin (which is an username) is still being shown on the comments made by the me, instead of MY NAME. So in order to achieve this we only have to make a mall update to the Comments.ascx file as follows.&lt;/p&gt;
&lt;p&gt;Replace the line of the name paragraph inside of the comment div with this one:&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;Mr.&amp;nbsp;&amp;lt;strong&amp;gt;&amp;lt;%=Html.LinkOrDefault((Model.PartialModel.Child.Creator.Name.ToLower() == &quot;admin&quot;) ?
    Model.PartialModel.Child.Creator.DisplayName : Model.PartialModel.Child.Creator.Name.CleanText(), 
&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;Model.PartialModel.Child.Creator.Url.CleanHref())%&amp;gt;&amp;lt;/strong&amp;gt;&lt;/pre&gt;
    </content>
  </entry>
  <entry>
    <title type="html">TIP/Trick: Enable/Disable ASP .NET Ajax TabContainer Tabs</title>
    <link rel="alternate" type="text/html" href="http://mrroa.com/Blog/TIPTrick-EnableDisable-ASP-NET-Ajax-TabContainer-Tabs"/>
    <id>http://mrroa.com/Blog/TIPTrick-EnableDisable-ASP-NET-Ajax-TabContainer-Tabs</id>
    <updated>2009-12-02T10:57:40.58</updated>
    <published>2009-12-01T14:20:00</published>
    <author>
      <name>Admin</name>
    </author>
    <category term="jquery" />
    <category term="tips" />
    <category term="ajax" />
    <category term="tabs" />
    <content type="html" xml:lang="en">
      &lt;p&gt;Space and content distribution is a very important part when designing a web site. That's why breaking content into multiple sections using a tabbed widget in order to save space is commonly used technique in web design these days.&lt;/p&gt;
&lt;p&gt;Today I'm going to address a common issue that arises when using a tab widget, which is enabling/disabling specific tabs. But first let's talk a little bit about the &lt;a href=&quot;http://www.asp.net/ajax/AjaxControlToolkit/Samples/&quot; target=&quot;_blank&quot;&gt;Ajax Control Toolkit&lt;/a&gt;. The Ajax Control Toolkit provides a palette of AJAX enabled controls, with the purpose of creating an &quot;interactive web experience&quot;. If you work with ASP .NET, you MUST have heard about &lt;a href=&quot;http://www.asp.net/ajax/&quot; target=&quot;_blank&quot;&gt;ASP .NET AJAX&lt;/a&gt;, previously known as ATLAS. You must also have seen and feel familiar with update panels and Microsoft's ASP .NET AJAX paradigm. Certainly the ASP .NET AJAX framework makes AJAX implementation trivial to anyone.&lt;/p&gt;
&lt;p&gt;The tendency of throwing update panels everywhere in order to achieve partial post backs in your page it's a widely used approach among ASP .NET AJAX enabled sites. It's also a common practice to see how every server/client side control on a web page, get replaced with any equivalent found on the AJAX Toolkit provided by Microsoft. If you are using one of these &quot;cutting edge&quot; techniques my friend, let me tell you that you are killing your application performance. And that also, I'm NOT the first one to point this out. The ASP .NET AJAX framework and the AJAX Toolkit have been widely criticized over thousands of technical web blogs. Mainly because by providing a mechanism for &quot;easy&quot; AJAX implementation performance of your web application gets compromised.&lt;/p&gt;
&lt;p&gt;Basically,&amp;nbsp;performance get
&lt;script src=&quot;../../../Skins/Default/Scripts/tiny_mce/themes/advanced/langs/en.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;../../../Skins/Default/Scripts/tiny_mce/themes/advanced/langs/en.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
s affected because a lot of web resources get imported when using both the framework and the toolkit. Also the fact that in every &quot;partial post back&quot; you actually send the whole page making HTTP GET/POST actions more bloated when loading your page. You could use Mozilla Firefox's Firebug plugin to analyze your HTTP requests and the amount of data that gets sent back and forth to the server, or just google about the topic in order to extend your knowledge about this particular subject.&lt;/p&gt;
&lt;p&gt;I encourage you guys to use other lightweight javascript frameworks that help you achieve DOM manipulation and asynchronous calls to the server in order to retrieve and send data like &lt;a href=&quot;http://www.jquery.com/&quot; target=&quot;_blank&quot;&gt;jQuery&lt;/a&gt; or &lt;a href=&quot;http://www.prototypejs.org/&quot; target=&quot;_blank&quot;&gt;Prototype&lt;/a&gt;.&lt;/p&gt;
&lt;h3&gt;Show me the code!&lt;/h3&gt;
&lt;p&gt;So I decided to do two examples instead of one. Besides doing it using the AJAX Control Toolkit. I also did it using jQuery, just to have two options. So here's the code.&lt;/p&gt;
&lt;h4&gt;AJAX Control Toolkit Tab Container&lt;/h4&gt;
&lt;p&gt;Here's the HTML:&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&amp;lt;div style=&quot;width: 500px&quot;&amp;gt;
  &amp;lt;cc1:TabContainer ID=&quot;TabContainer1&quot; runat=&quot;server&quot;&amp;gt;
      &amp;lt;cc1:TabPanel Hea&lt;script src=&quot;../../../Skins/Default/Scripts/tiny_mce/themes/advanced/langs/en.js&quot; type=&quot;text/javascript&quot;&gt;&lt;!--mce:2--&gt;&lt;/script&gt;derText=&quot;Tab 1&quot; runat=&quot;server&quot; ID=&quot;tpTab1&quot;&amp;gt;
          &amp;lt;ContentTemplate&amp;gt;
                Tab 1 Content!
          &amp;lt;/ContentTemplate&amp;gt;
      &amp;lt;/cc1:TabPanel&amp;gt;
      &amp;lt;cc1:TabPanel HeaderText=&quot;Tab 2&quot; runat=&quot;server&quot; ID=&quot;tpTab2&quot;&amp;gt;
          &amp;lt;ContentTemplate&amp;gt;
                Tab 2 Content!
          &amp;lt;/ContentTemplate&amp;gt;
      &amp;lt;/cc1:TabPanel&amp;gt;
  &amp;lt;/cc1:TabContainer&amp;gt;
  &amp;lt;p&amp;gt;
      &amp;lt;input type=&quot;button&quot; onclick=&quot;javascript:DisableEnableTab(false,0);&quot; value=&quot;Disable Tab 1&quot; /&amp;gt;
  &amp;lt;/p&amp;gt;         
&amp;lt;/div&amp;gt;
&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;And here's the javascript:&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;function DisableEnableTab(boolVal, tabIndex) {
      var tab = $find('&amp;lt;%=TabContainer1.ClientID%&amp;gt;');
      tab.get_tabs()[tabIndex].set_enabled(boolVal);
}
&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h3&gt;jQuery&lt;/h3&gt;
&lt;p&gt;Here's the HTML:&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&amp;lt;div id=&quot;tabs&quot; style=&quot;width: 500px&quot;&amp;gt;
      &amp;lt;ul&amp;gt;
          &amp;lt;li&amp;gt;&amp;lt;a href=&quot;#tab-1&quot;&amp;gt;&amp;lt;span&amp;gt;One&amp;lt;/span&amp;gt;&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
          &amp;lt;li&amp;gt;&amp;lt;a href=&quot;#tab-2&quot;&amp;gt;&amp;lt;span&amp;gt;Two&amp;lt;/span&amp;gt;&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
      &amp;lt;/ul&amp;gt;
      &amp;lt;div id=&quot;tab-1&quot;&amp;gt;
          Tab 1 Content!
      &amp;lt;/div&amp;gt;
      &amp;lt;div id=&quot;tab-2&quot;&amp;gt;
          Tab 2 Content!
     &amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;
&amp;lt;p&amp;gt;
   &amp;lt;input type=&quot;button&quot; onclick=&quot;javascript:DisableTab();&quot; value=&quot;Disable Tab 1&quot; /&amp;gt;
&amp;lt;/p&amp;gt;
&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;And here's the javascript:&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;$(document).ready(function() {
      $(&quot;#tabs&quot;).tabs();
 });
            
 function DisableTab() {
       //Selecting another tab
      $(&quot;#tabs&quot;).tabs('select', 1);
                
      //Disabling first tab
      $(&quot;#tabs&quot;).tabs('option', 'disabled', [0]);
 }
&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;So there it is, happy coding!&lt;/p&gt;
    </content>
  </entry>
  <entry>
    <title type="html">Can URI and URL be used interchangeably ?!</title>
    <link rel="alternate" type="text/html" href="http://mrroa.com/Blog/Can-URI-and-URL-be-used-interchangeably-"/>
    <id>http://mrroa.com/Blog/Can-URI-and-URL-be-used-interchangeably-</id>
    <updated>2009-10-28T17:50:05.403</updated>
    <published>2009-10-28T13:52:00</published>
    <author>
      <name>Admin</name>
    </author>
    <category term="URN" />
    <category term="WWW" />
    <category term="URI" />
    <category term="W3C" />
    <category term="URL" />
    <content type="html" xml:lang="en">
      &lt;p&gt;Have you encountered yourselves hesitating when trying to use the terms URI or URL? I have.&amp;nbsp;Apparently the difference between a URI and a URL is a very debated topic on the web. And it's also a source of&amp;nbsp;confusion&amp;nbsp;for many people, including myself.&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Almost every comparison that I find seem to be a tongue-twister, which vaguely describes that they are related but they're not the same (aha! you see? I did it too, I said something but actually said nothing. PLOP!). The truth is that there's a different RFC describing the scheme of each, URI's and URL's. If you go through the W3C documentation you'll find that they have a &lt;a href=&quot;http://www.w3.org/TR/uri-clarification/&quot; target=&quot;_blank&quot;&gt;documentation page&lt;/a&gt; trying to clarify the confusion around URI's.&lt;/p&gt;
&lt;h3&gt;In the end? What's are URI's and what are URL's?&lt;/h3&gt;
&lt;p&gt;The &lt;a href=&quot;http://www.ietf.org/rfc/rfc2396.txt&quot; target=&quot;_blank&quot;&gt;RFC2396&lt;/a&gt; describes a Uniform Resource Identifier (URI) as a set of characters used to identify a resource name, location or both on the internet. This means that an URI can be classified as a locator (URL), a name (URN), or both.&amp;nbsp;The &lt;a href=&quot;http://tools.ietf.org/html/rfc2717&quot; target=&quot;_blank&quot;&gt;RFC2717&lt;/a&gt;&amp;nbsp;describes a &quot;Uniform Resource Locator&quot; (URL)&amp;nbsp;as a compact string representation of the location for a resource that is available via the Internet.&amp;nbsp;Parting from these definitions we can conclude that every time we refer to a URL we are talking about an URI, but not the other way.&lt;/p&gt;
&lt;h3&gt;So? Can we use them interchangeably?&lt;/h3&gt;
&lt;p&gt;The short answer is, NO. Even though its a tendency among experts, &lt;a href=&quot;http://tools.ietf.org/html/draft-mealling-uri-ig-00&quot; target=&quot;_blank&quot;&gt;this&lt;/a&gt; World Wide Web Consortium memo states that there shouldn't be any confusion, since they all have different schemes (URI's, URL's and URN's) describing the differences among them. BUT!!! If we are talking about &quot;how to identify the resource and provide the means of locating the resource by describing it's primary access mechanism&quot; then we are talking about an URL, which is also an URI; therefore we can use them interchangeably in that specific case.&lt;/p&gt;
&lt;h3&gt;Conclusion&lt;/h3&gt;
&lt;p&gt;When talking about Internet resources we tend to use these terms to refer to them, specially when talking about HTTP actions in order to get a document. So, there's always the safe way of doing things: if you don't know if you are talking an URL or an URI, just
&lt;script src=&quot;../../../Skins/Default/Scripts/tiny_mce/themes/advanced/langs/en.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
refer to it as an URI and you wont be wrong.&lt;/p&gt;
    </content>
  </entry>
  <entry>
    <title type="html">Oxite: Customizing the comments area</title>
    <link rel="alternate" type="text/html" href="http://mrroa.com/Blog/Oxite-Customizing-the-comments-area"/>
    <id>http://mrroa.com/Blog/Oxite-Customizing-the-comments-area</id>
    <updated>2009-12-11T12:28:58.97</updated>
    <published>2009-10-27T05:19:00</published>
    <author>
      <name>Admin</name>
    </author>
    <category term="recaptcha" />
    <category term="Oxite" />
    <content type="html" xml:lang="en">
      &lt;p&gt;Continuing my Oxite series of blog posts I'll address the comments area. For my taste oxite is missing a couple of things on the comments listing and comments posting department. It doesn't have a way to ensure that the comment being posted is not being generated by a bot. I've already been a victim of this and to be honest I'm not a fan of SPAM, so let's stop that!&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;http://s.mrroa.com/oxite-spam.png&quot; alt=&quot;&quot; width=&quot;727&quot; height=&quot;314&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Oxite also doesn't have a special style for comments posted by the site admin. In this blog post we are going to address this issues by implementing a css class that helps the reader identify a site administrator comment from a blog comment's list and a &lt;a title=&quot;Captcha&quot; href=&quot;http://en.wikipedia.org/wiki/CAPTCHA&quot; target=&quot;_blank&quot;&gt;captcha&lt;/a&gt; validation for the comments input.&lt;/p&gt;
&lt;p&gt;For these tasks I'll be using css and &lt;a title=&quot;Re Captcha&quot; href=&quot;http://recaptcha.net/&quot; target=&quot;_blank&quot;&gt;reCAPTCHA&lt;/a&gt;, which is owned by google and it's widely used among popular sites as Facebook, The New York Times, StackOverflow, TicketMaster, etc. It's worth pointing out that reCaptcha was initially conceived in Carnegie Mellon University, where the term &quot;CAPTCHA&quot; was initially coined. The term contrives from the acronym&amp;nbsp; &quot;&lt;strong&gt;C&lt;/strong&gt;ompletely &lt;strong&gt;A&lt;/strong&gt;utomated &lt;strong&gt;P&lt;/strong&gt;ublic &lt;strong&gt;T&lt;/strong&gt;uring test to tell &lt;strong&gt;C&lt;/strong&gt;omputers and &lt;strong&gt;H&lt;/strong&gt;umans &lt;strong&gt;A&lt;/strong&gt;part.&quot;&lt;/p&gt;
&lt;p&gt;So putting the theory to a side, let's start getting things done!&lt;/p&gt;
&lt;h3&gt;Styling the Admin comments&lt;/h3&gt;
&lt;p&gt;When the admin posts a comment Oxite automatically adds an &quot;Admin&quot; class to the li element from the comments list. This means that styling the comment won't be very hard since the only thing to do is add a custom style for this class. I chose a beige tone as the background of the Admin comments and added the following to the site stylesheet (site.css)&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;ul.comments.medium li.Admin
{
    background: #FFFFC0;
}&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;And tha
&lt;script src=&quot;../../../Skins/Default/Scripts/tiny_mce/themes/advanced/langs/en.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;../../../Skins/Default/Scripts/tiny_mce/themes/advanced/langs/en.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
t's it, from now on my comments will have a beige like background. That was easy wasn't it? Good let's keep moving!&lt;/p&gt;
&lt;h3&gt;Implementing reCAPTCHA&lt;/h3&gt;
&lt;p&gt;Moving on to the CAPTCHA part, we have to do a couple things before starting. First register at&amp;nbsp;&lt;a title=&quot;Re Captcha&quot; href=&quot;http://recaptcha.net/&quot; target=&quot;_blank&quot;&gt;reCAPTCHA&lt;/a&gt;, download the .NET dll and reference it from Oxite.Mvc project. After that the first thing to do is create an Action Filter Attribute. There's already a directory containing existing Filters for Oxite on the Oxite.Mvc project so let's place ours there.&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;namespace Oxite.Mvc.ActionFilters
{
&amp;nbsp;&amp;nbsp; &amp;nbsp;public class CaptchaAttribute : ActionFilterAttribute
&amp;nbsp;&amp;nbsp; &amp;nbsp;{
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;private const string ChallengeFieldKey = &quot;recaptcha_challenge_field&quot;;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;private const string ResponseFieldKey = &quot;recaptcha_response_field&quot;;

&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;public override void OnActionExecuting(ActionExecutingContext filterContext)
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{
            //Getting the user parameter from the current context
            var user = (Model.User)filterContext.ActionParameters[&quot;currentUser&quot;];
            if (user != null &amp;amp;&amp;amp; user.Name == &quot;Admin&quot;)
            {
                filterContext.ActionParameters[&quot;captchaValid&quot;] = true;
                return;
            }
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;var captchaChallengeValue = filterContext.HttpContext.Request.Form[ChallengeFieldKey];
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;var captchaResponseValue = filterContext.HttpContext.Request.Form[ResponseFieldKey];

&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;var captchaValidtor = new Recaptcha.RecaptchaValidator
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;PrivateKey = &quot;YOUR PRIVATE KEY GOES HERE&quot;,
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;RemoteIP = filterContext.HttpContext.Request.UserHostAddress,
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Challenge = captchaChallengeValue,
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Response = captchaResponseValue
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;};

&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;var recaptchaResponse = captchaValidtor.Validate();
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;filterContext.ActionParameters[&quot;captchaValid&quot;] = recaptchaResponse.IsValid;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;base.OnActionExecuting(filterContext);

&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}
&amp;nbsp;&amp;nbsp; &amp;nbsp;}
}&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;In order to render the reCAPTCHA widget we are going to add a new helper to the Html helper Extensions class. The helper is going to ease the implementation by encapsulating everything to a method call. Our new extension method should look like this:&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;#region ReCaptcha
public static string RenderCaptcha(this HtmlHelper helper)
{
&amp;nbsp; &amp;nbsp; &amp;nbsp; var captchaControl = new Recaptcha.RecaptchaControl
 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{
 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ID = &quot;recaptcha&quot;,
 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Theme = &quot;clean&quot;,
 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;PublicKey = &quot;YOUR PUBLIC KEY GOES HERE&quot;,
 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;PrivateKey = &quot;YOUR PRIVATE &lt;script src=&quot;../../../Skins/Default/Scripts/tiny_mce/themes/advanced/langs/en.js&quot; type=&quot;text/javascript&quot;&gt;&lt;!--mce:2--&gt;&lt;/script&gt;KEY GOES HERE&quot;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;};

&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;var htmlWriter = new HtmlTextWriter(new StringWriter());
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;captchaControl.RenderControl(htmlWriter);
 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return htmlWriter.InnerWriter.ToString();
}
#endregion&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Now we are ready for the implementation. From here we just need to add our Action Filter Attribute on the Controller method that creates the post comment. The Controller is located on the same project as the Action Filers, Oxite.Mvc. The comments are created on the PostController. There we need to add our Action Filter Attribute to the AddComment method. Also we need to change the method signature by adding a new overload by adding a new variable to contain our reCAPTCHA validation result.&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;[CaptchaValidator]
[ActionName(&quot;Item&quot;), AcceptVerbs(HttpVerbs.Post)]
public virtual object AddComment(Area areaInput, PostBase postBaseInput, Comment commentInput, UserBase userBaseInput,&amp;nbsp;
                                   UserBase currentUser,&amp;nbsp;bool? remember, bool? subscribe, bool? captchaValid)&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Now the success of the CAPTCHA validation is going to be contained on the added boolean value. Notice that the type is marked as nullable, this is because the method is initialized with null values on the OxiteApplication class.&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;itemActionCriteria.AddMethod(p =&amp;gt; p.AddComment(null, null, null, null, null, null, null, null));&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Great, so now we have almost everything in place. I used a quick &amp;amp; dirty approach in order to raise the form validation when a the introduced string does not match the one displayed by the reCAPTCHA widget. In case the captchaValid variable is false I just set the comment on the&amp;nbsp;&lt;span style=&quot;white-space: pre;&quot;&gt;commentInput object to String.Empty.&lt;span style=&quot;white-space: normal;&quot;&gt;&amp;nbsp;This will set the validationState object IsValid flag to false, which is Oxite's form validation mechanism.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;&lt;span style=&quot;white-space: normal;&quot;&gt;Now the only thing left to do is go to the&amp;nbsp;CommentFromAnonymous.ascx user control. This is what renders the actual comment form on the post. Here we are going to add our Html helper extension method in order to render the reCAPTCHA widget and finally add some validation to the post comment form. I decided to place my widget under the actual comment text area. The call to the extension method looks like this:&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&amp;lt;div class=&quot;recaptcha&quot;&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;lt;%= Html.RenderCaptcha() %&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;/pre&gt;
&lt;h3&gt;Summary&lt;/h3&gt;
&lt;p&gt;In this blog post I added an extra, yet important, feature to Oxite: CAPTCHA validation. Once again, I was able to extend the current core with ease and added reCAPTCHA's widget. I'm so glad I did this, since I wont have to deal with spam comments anymore :). Stay tuned for some other Oxite extensions and more praising of the MVC paradigm!&lt;/p&gt;
    </content>
  </entry>
  <entry>
    <title type="html">How to: Write your own Visual Studio Code Snippets</title>
    <link rel="alternate" type="text/html" href="http://mrroa.com/Blog/How-to-Write-your-own-Visual-Studio-Code-Snippets"/>
    <id>http://mrroa.com/Blog/How-to-Write-your-own-Visual-Studio-Code-Snippets</id>
    <updated>2010-02-28T08:39:12.87</updated>
    <published>2009-09-21T13:22:00</published>
    <author>
      <name>Admin</name>
    </author>
    <category term="snippets" />
    <category term="visualstudio" />
    <content type="html" xml:lang="en">
      &lt;p&gt;Just to go with the formality flow, let's first define a snippet. According to&amp;nbsp;&lt;a href=&quot;http://en.wikipedia.org/wiki/Code_snippets&quot; target=&quot;_blank&quot;&gt;wikipedia,&lt;/a&gt;&lt;strong&gt;&amp;nbsp;&lt;/strong&gt;a&lt;strong&gt;&amp;nbsp;Code Snippet&lt;/strong&gt;&amp;nbsp;is a programming term for a small region of re-usable source code or text. Ordinarily, these are formally-defined operative units to incorporate into larger programming modules. Snippets are often used to clarify the meaning of an otherwise &quot;cluttered&quot; function, or to minimize the use of repeated code that is common to other functions.&lt;/p&gt;
&lt;p&gt;Visual studio allows us to add our own code snippets for reuse of common block codes in current or further projects. Custom code snippets can be adhered to the ones bundled with the IDE. These can be created and edited with the text editor of your preference. Snippets are handled as XML files, which follow a &lt;a title=&quot;Code Snippet XML Schema&quot; href=&quot;http://msdn.microsoft.com/en-us/library/ms171418.aspx&quot; target=&quot;_blank&quot;&gt;XML Schema&lt;/a&gt; from Microsoft. This schema contains the definition of mandatory elements and attributes for the snippet to work.&lt;/p&gt;
&lt;p&gt;Since the 2005 release, code snippets were introduced as part of Visual Studio. Visual Studio 2005/2008 itself has pre-bundled snippets for surrounding or inserting code blocks. Visual Studio also allows code snippets to be added to the toolbar by simply pasting the code block into it. You could create different tabs to classify them.&lt;/p&gt;
&lt;h3&gt;How to create your own custom code snippet in Visual Studio 2005/2008&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;1.&lt;/strong&gt; To start, let's create an XML file with a *.snippet extension. This file will contain our snippet attributes, as well as the desired code block.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;http://s.mrroa.com/codesnippetsstep1.PNG&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;2.&lt;/strong&gt; Ironically, let's use the &quot;snippet&quot; snippet which comes pre-bundled with Visual Studio. This will inject into our file the snippet XML structure.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;http://s.mrroa.com/codesnippetsstep2.PNG&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;p&gt;3. Edit the snippet template by filling in the necessary values.The type for the snippets may vary depending on what we want to achieve, we may only want to insert a block code, or surround one with the desired snippet as well. The declarations correspond to de variables that may be edited from the code edit
&lt;script src=&quot;http://www.mrroa.com/Skins/Default/Scripts/tiny_mce/themes/advanced/langs/en.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
or (Visual Studio) and they must be referred between $ on the code element. We must specify for what language is the snippet as well.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;http://s.mrroa.com/codesnippetsstep3.PNG&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;p&gt;4. After editing the file, the next step is to open the Code Snippets Manager from the tools menu. On the Code Snippets Manager by selecting add, we are going to be able to add a complete folder containing our code snippets. If we want to import one specific snippet into a selected folder we just have to click on Import.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;http://s.mrroa.com/codesnippetsstep4.PNG&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;h3&gt;Using our custom code snippet&lt;/h3&gt;
&lt;p&gt;So let's use our code snippet. We can select it from the insert code snippet in the Visual Studio context menu (right click on the class file), or we can use our defined shortcut and press tab twice to import the block of code.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;http://s.mrroa.com/codesnippetsstep5.PNG&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;h3&gt;The Result!&lt;/h3&gt;
&lt;p&gt;So here it is ladies and gentlemen, our custom code snippet!&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;http://s.mrroa.com/codesnippetsstep6.PNG&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;h3&gt;Summary&lt;/h3&gt;
&lt;p&gt;The purpose of this article is to highlight a very useful feature from Microsoft's IDE. A cool feature we should exploit in order to gain the most of it, and that not many people gets to take advantage of. Grabbing a code block that is constantly reused and insert it from with the help of the IDE whenever we need it, boosts our productivity significantly. Also, this feature encourages the developer to embrace re-usability when designing a piece of code.&lt;/p&gt;
    </content>
  </entry>
  <entry>
    <title type="html">Oxite: Meets TinyMCE</title>
    <link rel="alternate" type="text/html" href="http://mrroa.com/Blog/Oxite-meets-TinyMCE"/>
    <id>http://mrroa.com/Blog/Oxite-meets-TinyMCE</id>
    <updated>2009-10-05T02:56:10.993</updated>
    <published>2009-09-16T10:11:00</published>
    <author>
      <name>Admin</name>
    </author>
    <category term="TinyMCE" />
    <category term="Oxite" />
    <content type="html" xml:lang="en">
      &lt;p&gt;This is the first of a series of blog posts I'll be doing about Oxite, a simple blog engine written using ASP .NET MVC. Which happens to be the one I'm using to administrate and maintain my blog. On my &lt;a title=&quot;Mr. Roa&quot; href=&quot;../../../Blog/Hello-World&quot;&gt;first post&lt;/a&gt;&amp;nbsp;I stated that I intended to modify the blogging engine and complete it &lt;strong&gt;&lt;em&gt;my way&lt;/em&gt;&lt;/strong&gt;. I already created a list of features, that I'd like to see in it in order to get things going.&lt;/p&gt;
&lt;p&gt;So, according to &lt;strong&gt;ME&lt;/strong&gt;, the first &quot;missing&quot; feature in Oxite, is a wysiwyg. I know it can be integrated with &lt;a title=&quot;Using Windows Live Writer to publish in Oxite &quot; href=&quot;http://capitalcoder.com/Blog/Using-Windows-Live-Writer-with-Oxite&quot; target=&quot;_blank&quot;&gt;live writer&lt;/a&gt;, but c'mon a blog engine shouldn't rely on third party applications, even though integration with those it's a nice feature. A blog engine should provide an easy to use text formatting tool. At least for the body of the blog post, taking care of annoying formatting tasks which involve a lot of html markup. With that said, after this blog post I won't be writing html markup directly into a textarea in order to format my blog posts.&lt;/p&gt;
&lt;p&gt;Let's get this thing started then. After a browsing through an extensive list of available &lt;span class=&quot;subhead&quot;&gt;&lt;span style=&quot;font-family: Verdana;&quot;&gt;&lt;a href=&quot;http://www.geniisoft.com/showcase.nsf/WebEditors&quot; target=&quot;_blank&quot;&gt;TTW (&quot;Through the Web&quot;) WYSIWYG Web Editors&lt;/a&gt;, I chose to use &lt;a href=&quot;http://tinymce.moxiecode.com/&quot; target=&quot;_blank&quot;&gt;TinyMCE&lt;/a&gt;. It's widely used, it has a lot of plugins, an active community and it seems really easy to implement.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;subhead&quot;&gt;&lt;span style=&quot;font-family: Verdana;&quot;&gt;Well, I'm done with the first step. I already chose my formatting tool for my blog posts. Anyways I created a little list of things I MUST be able to do when creating a blog post with it:&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;span class=&quot;subhead&quot;&gt;&lt;span style=&quot;font-family: Verdana;&quot;&gt;Use default formatting tools such as bold text, italic, underline, text alignment and justification, etc.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;subhead&quot;&gt;&lt;span style=&quot;font-family: Verdana;&quot;&gt;Have a html view in case I need to teak some of the markup after all.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;subhead&quot;&gt;&lt;span style=&quot;font-family: Verdana;&quot;&gt;An option to wrap text between pre or code tags in order to identify code snippets.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;subhead&quot;&gt;&lt;span style=&quot;font-family: Verdana;&quot;&gt;Spellchecker, of course! This is one of the most useful features when creating articles/posts. (isn't it?)&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Ok, after getting that out of the way. Let's get started shall we?&lt;/p&gt;
&lt;h3&gt;TinyMCE &amp;amp; Code Snippet Wrapping&lt;/h3&gt;
&lt;p&gt;&lt;span class=&quot;subhead&quot;&gt;&lt;span style=&quot;font-family: Verdana;&quot;&gt;In order to get started we need to download TinyMCE, also since one of our requirements is to wrap code snippets between pre/code tags we will need something to make code snippets look prettier. For that matter I'll be using &lt;a href=&quot;http://code.google.com/p/google-code-prettify/&quot; target=&quot;_blank&quot;&gt;prettify&lt;/a&gt;. After downloading both, the script files must be placed inside the Scripts folder of the Oxite theme being used.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;http://s.mrroa.com/tinymcescripts.png&quot; alt=&quot;&quot; width=&quot;269&quot; height=&quot;285&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Prettify also comes with a stylesheet that defines the color schema of our code snippets, so we should also place that file inside of the Styles folder of the Oxite theme.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;http://s.mrroa.com/tinymcestyles.png&quot; alt=&quot;&quot; width=&quot;269&quot; height=&quot;285&quot; /&gt;&lt;/p&gt;
&lt;p&gt;For my taste the code snippet text should be big and clear, so I changed the cascading style sheet to render the code snippet fonts a little bit bigger.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;http://s.mrroa.com/prettifyfontsize.png&quot; alt=&quot;&quot; width=&quot;751&quot; height=&quot;336&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Ok, so now we are closer to having a WYSIWYG with support to paste code snippets in Oxite, but first there are a couple more steps we need to do. In order to be a little bit more organized I created a mrroa.com.js file which is going to contain my client side &lt;em&gt;extensions&lt;/em&gt;. Here we are going to place the initialization script for tinymce as follows.&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;tinyMCE.init({&lt;br /&gt;    mode: &quot;exact&quot;,&lt;br /&gt;    elements: &quot;post_body&quot;,&lt;br /&gt;    theme: &quot;advanced&quot;,&lt;br /&gt;    theme_advanced_buttons1: &quot;codetag,code,separator,bold,italic,underline,strikethrough,separator,justifyleft,&lt;br /&gt;    justifycenter,justifyright,justifyfull,separator,bullist,numlist,separator,undo,redo,separator,link,unlink&quot;,&lt;br /&gt;    theme_advanced_buttons2: &quot;&quot;,&lt;br /&gt;    theme_advanced_buttons3: &quot;&quot;,&lt;br /&gt;    theme_advanced_toolbar_location: &quot;top&quot;,&lt;br /&gt;    theme_advanced_toolbar_align: &quot;left&quot;,&lt;br /&gt;    theme_advanced_statusbar_location: &quot;bottom&quot;,       &lt;br /&gt;    setup: function(ed) {&lt;br /&gt;        //Custom button Code (Code Snippet Wrapper)&lt;br /&gt;        ed.addButton('codetag', {&lt;br /&gt;            title: 'Wrap code tags around selected text',&lt;br /&gt;            image: 'http://mrroa.com/Content/images/code.gif',&lt;br /&gt;            onclick: function() {&lt;br /&gt;                ed.selection.setContent('&amp;lt;pre class=&quot;prettify&quot;&amp;gt;' &lt;br /&gt;                     + ed.selection.getContent({ format: 'text' }) + '&amp;lt;/pre&amp;gt;');             &lt;br /&gt;             }         &lt;br /&gt;         });     &lt;br /&gt;      } });&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;Notice that there's a setup property which contains a javascript function. This is the definition of our code wrapping button, that is not included in TinyMCE's palette of buttons. The setup section in the above snippet, tells TinyMCE to wrap around pre tags our text selection. Also notice how I added the default text formatting tools into the theme_advanced_buttons1 collection. The &lt;span style=&quot;text-decoration: underline;&quot;&gt;&lt;em&gt;code&lt;/em&gt;&lt;/span&gt; button represents the html source viewer, so this WYSIWYG almost has all the features described initially.&lt;/p&gt;
&lt;h3&gt;SpellChecking&lt;/h3&gt;
&lt;p&gt;For this feature we need to work a little bit more. First of all we need to download and reference the TinyMCE &lt;a href=&quot;http://tinymce.moxiecode.com/download.php&quot; target=&quot;_blank&quot;&gt;.NET Package&lt;/a&gt;. Among many features embedded, this package contains a handler which implements the old google spellchecking API, which still works (I figure that eventually they will update the hanlder to implement the new one).&lt;/p&gt;
&lt;p&gt;After referencing the package we need to add the following code to the httpHandlers section of our web.config.&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&amp;lt;add verb=&quot;GET,HEAD,POST&quot; path=&quot;TinyMCE.ashx&quot; type=&quot;Moxiecode.TinyMCE.Web.HttpHandler,Moxiecode.TinyMCE&quot; /&amp;gt;&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;Also we need to add a rule to the Oxite Routing class, in order to tell the ASP .NET MVC routing engine that it shouldn't map to a controller the requests made to the hanlder.&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;routes.Add(new Route(&quot;TinyMCE.ashx&quot;, new StopRoutingHandler()))&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Now we just need to update the script file containing the TinyMCE initialization to implement the spellchecker plugin.&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;tinyMCE.init({&lt;br /&gt;    mode: &quot;exact&quot;,&lt;br /&gt;    elements: &quot;post_body&quot;,&lt;br /&gt;    theme: &quot;advanced&quot;,&lt;br /&gt;    plugins: &quot;spellchecker&quot;,&lt;br /&gt;    theme_advanced_buttons1: &quot;codetag,code,separator,bold,italic,underline,strikethrough,separator,justifyleft,&lt;br /&gt;    justifycenter,justifyright,justifyfull,separator,bullist,numlist,separator,undo,redo,separator,link,unlink,separator,&lt;br /&gt;    spellchecker&quot;,&lt;br /&gt;    theme_advanced_buttons2: &quot;&quot;,&lt;br /&gt;    theme_advanced_buttons3: &quot;&quot;,&lt;br /&gt;    theme_advanced_toolbar_location: &quot;top&quot;,&lt;br /&gt;    theme_advanced_toolbar_align: &quot;left&quot;,&lt;br /&gt;    theme_advanced_statusbar_location: &quot;bottom&quot;,      &lt;br /&gt;    spellchecker_languages: &quot;+English=en,Spanish=es&quot;,&lt;br /&gt;    spellchecker_rpc_url: &quot;/TinyMCE.ashx?module=SpellChecker&quot;,&lt;br /&gt;    setup: function(ed) {&lt;br /&gt;        //Custom button Code (Code Snippet Wrapper)&lt;br /&gt;        ed.addButton('codetag', {&lt;br /&gt;            title: 'Wrap code tags around selected text',&lt;br /&gt;            image: 'http://mrroa.com/Content/images/code.gif',&lt;br /&gt;            onclick: function() {&lt;br /&gt;                ed.selection.setContent('&amp;lt;pre class=&quot;prettify&quot;&amp;gt;' &lt;br /&gt;                     + ed.selection.getContent({ format: 'text' }) + '&amp;lt;/pre&amp;gt;');             &lt;br /&gt;             }         &lt;br /&gt;         });     &lt;br /&gt;      } });&lt;/pre&gt;
&lt;h3&gt;One Final Step&lt;/h3&gt;
&lt;p&gt;Now we need to reference the scripts and stylesheets on the master pages of the site. In order to achieve this we need to place this snippets in two webusercontrols.&lt;/p&gt;
&lt;p&gt;First in HeadCustomAdminContents.ascx&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;Html.RenderScriptTag(&quot;tiny_mce/tiny_mce_src.js&quot;);&lt;br /&gt;Html.RenderScriptTag(&quot;mrroa.com.js&quot;);&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;And then in HeadCustomContents.ascx&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;Html.RenderCssFile(&quot;prettify.css&quot;);&lt;br /&gt;Html.RenderScriptTag(&quot;prettify/prettify.js&quot;);&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h3&gt;The Result&lt;/h3&gt;
&lt;p&gt;Here's a screenshot of my nice and shiny WYSIWYG with all the features I wanted. I guess you can tell I used it to create this post as well ;)&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;http://s.mrroa.com/tinymce.png&quot; alt=&quot;&quot; width=&quot;945&quot; height=&quot;282&quot; /&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h3&gt;Summary&lt;/h3&gt;
&lt;p&gt;In this post, I tried to emphasize on the importance of having text formatting tools like &lt;strong&gt;WYSIWYG&lt;/strong&gt;'s in systems used for publishing. Also I tried to show how to implement TinyMCE, which is widely used, and how to extend it for some specific purposes. Furthermore, this series of articles purpose is to demonstrate how the MVC model allows to achieve with ease extensibility, modifiability and testability.&lt;/p&gt;
    </content>
  </entry>
  <entry>
    <title type="html">World.Hello()</title>
    <link rel="alternate" type="text/html" href="http://mrroa.com/Blog/Hello-World"/>
    <id>http://mrroa.com/Blog/Hello-World</id>
    <updated>2009-09-18T12:14:10.567</updated>
    <published>2009-09-09T01:28:00</published>
    <author>
      <name>Admin</name>
    </author>
    <category term="MrRoa" />
    <content type="html" xml:lang="en">
      &lt;p&gt;Woa! I'm nervous!!!! This is my first blog post. The intention of this blog is to provide technical insight on day to day web development tasks, based on my work related experience and also some of my personal projects/challenges. Personally I'm not biased when it comes to programming tools/languages (ok, maybe this is a lie :), but I got to admit I have a strong bond with C#, Visual Studio and the .NET framework itself. Therefore learning and sharing stuff about how to achieve things with those are going to be the main focus of my blog posts.&lt;/p&gt;
&lt;p&gt;Initially I thought about creating a blog engine from scratch and use that experience as a kickoff start, since, according to &lt;a title=&quot;Phil Haack&quot; href=&quot;http://haacked.com/archive/0001/01/01/Rolling_Your_Own_Blog_Engine.aspx&quot; target=&quot;_blank&quot;&gt;Phil Haack&lt;/a&gt; it should be the Hello World of web developers. However, I found &lt;a title=&quot;oxite&quot; href=&quot;http://www.codeplex.com/oxite&quot; target=&quot;_blank&quot;&gt;this&lt;/a&gt; blog engine half way done and considered that it would be a more &lt;strong&gt;interesting challenge&lt;/strong&gt; to complete it my way. With that said you have a glimpse of some of the content I'm going to be displaying here.&lt;/p&gt;
&lt;p&gt;I'd like to thank my friend &lt;a title=&quot;JoshJordan.com&quot; href=&quot;http://joshjordan.com&quot; target=&quot;_blank&quot;&gt;Josh Jordan&lt;/a&gt; for encouraging me to go through with this, and it's who also suggested the domain name.&lt;/p&gt;
&lt;p&gt;So here I start!&lt;/p&gt;
&lt;p&gt;Hello World!!!&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
    </content>
  </entry>
</feed>
