Tuesday, November 12, 2013

Installing Microsoft Office 2010 x32 in Wine - Ubuntu 12.04/12.10 64-bit/32-bit

I love using Linux... and Ubuntu is my favourite flavour... it's quite user-friendly and definitely powerful... and I prefer the debian packaging over RPM.

Now, Ubuntu ships with LibreOffice which is an amazing productivity suite, or you could install OpenOffice. For the most case, these work great for me. But since I work in a world dominated by Microsoft Office, I have to stick with the Microsoft document formats like Excel, Word, Powerpoint, Visio, etc. LibreOffice can definitely read and edit all these document types, but with the Microsoft Office XML documents (docx, xlsx, pptx...), formatting is often an issue. LibreOffice (and even OpenOffice) often cannot keep the formatting and styles intact, and this can be a real problem at time.

For me, moving to Windows is not an option I would choose, and running virtual machines really doesn't cut it. Fortunately, Wine 1.5 supports Microsoft Office 2010 quite seamlessly and it works great. So, here's what I did to get Microsoft Office 2010 up and running in Wine 1.5 under Ubuntu 12.04/12.10 64-bit/32-bit.

Install mesa OpenGL and the 32-bit libraries (Ubuntu 64-bit only)
sudo apt-get install mesa-utils mesa-utils-extra libgl1-mesa-glx:i386 libgl1-mesa-dev ia32-libs ia32-libs-multiarch libgl1-mesa-dri:i386 libglapi-mesa:i386 libgles2-mesa

Install mesa OpenGL (Ubuntu 32-bit only)
$ sudo apt-get install mesa-utils mesa-utils-extra libgl1-mesa-glx libgl1-mesa-dev
Create softlinks for the 32-bit OpenGL libraries (Ubuntu 64-bit only)
$ sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/mesa/libGL.so
$ sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so /usr/lib/i386-linux-gnu/libGL.so
Add the official Wine PPA to get the latest Wine version
$ sudo add-apt-repository ppa:ubuntu-wine/ppa
$ sudo apt-get update
$ sudo apt-get install wine
Create a 32-bit Wine prefix. This is important since only Microsoft Office 2010 32-bit works on Wine and you need a 32-bit Wine environment to run 32-bit Windows applications. The WINEPREFIX can be a location of your choice.
$ export WINEPREFIX="/home/minhphuc/.wineprefixes/office2010/"
$ export WINEARCH="win32"
Start up Winetricks via the same command window to install some required dependencies
$ winetricks
In the WineTricks window which opensh, select "Select the default wineprefix" and click OK. The new window which opens should have the WINEPREFIX location in the title
Winetricks - current prefix is "/home/minhphuc/.wineprefixes/office2010/"
Now select "Install a Windows DLL or component" and then select "dotnet20" and "msxml6" and follow the on-screen instructions.

Once that is done select "Install a font" and then select "corefonts"

Now, navigate to the location of the Microsoft Office 2010 installation and type
$ wine setup.exe
Follow the onscreen instructions and complete the installation. 

Once that is completestart up Winetricks via the same command window to configure some required libraries.
$ winetricks
Select "Run winecfg". Then select the "Libraries" tab. 

You should see "*msxml6 (native, built-in)" in the "Existing overrides" section. Highlight it and click Edit and select "Native (Windows)" and click OK. Now, it should show up as "*msxml6 (native)"

Then add the "riched20" and "gdiplus" libraries from the "New override for library" section and make sure these are also set as "Native"

Once that is complete, you should be able to run the Office programs you installed via the dash/menu icons.

http://craigacgomez.blogspot.com/2012/09/installing-microsoft-office-2010-in.html

Thursday, November 7, 2013

Ubuntu Tips & Tricks

1. Download Linux kernel

Step 1 : Ctrl + Alt + T
Step 2 : sudo apt-get install linux-headers-$(uname -r)
Step 3 : The path to the kernel headers is then /usr/src/linux-headers-$(uname -r)/include

2. Update Link kernel header

sudo ln -s /usr/src/linux-headers-$(uname -r)/include/generated/uapi/linux/version.h /usr/src/linux-headers-$(uname -r)/include/linux/version.h
 


3. Install Vmware on ubuntu

Before installing Vmware Workstation you need to install build-essential and linux headers
   sudo apt-get install build-essential linux-headers-$(uname -r)
and then
 sudo ln -s /usr/src/linux-headers-$(uname -r)/include/generated/uapi/linux/version.h /usr/src/linux-headers-$(uname -r)/include/linux/version.h


4.Uninstaller Vmware on Linux

  • First check which version is installed in your system.
[root@fedora-home ~]# vmware-installer   --list-products
Output:
Product Name           Product Version      ====================== ==================== vmware-workstation     7.0.0.203739
  • Second- Remove  the installed version of Vmware using the following  command :
[root@fedora-home ~]# vmware-installer   -u vmware-workstation


5. customize grub loader 

sudo add-apt-repository ppa:danielrichter2007/grub-customizer
sudo apt-get update
sudo apt-get install grub-customizer

Monday, August 12, 2013

Setup MVC ASP.NET in IIS

’ve seen a lot of reports where people have trouble getting ASP.NET MVC up and running on IIS 6. Sometimes the problem is a very minor misconfiguration, sometimes it’s a misunderstanding of how IIS 6 works.
In this post, I want to provide a definitive guide to getting ASP.NET MVC running on IIS 6. I will walk through using the .mvc or .aspx file extension for URLs first, then I will walkthrough using extension-less URLs.
If you’re running into problems with IIS 6 and ASP.NET MVC, I recommend trying to walk through all the steps in this post, even if you’re not interested in using the.mvc or .aspx mapping. Some of the lessons learned here have more to do with how ASP.NET itself works with IIS 6 than anything specific to ASP.NET MVC.

Initial Setup

To make this easy, start Visual Studio and create a new ASP.NET MVC Web Application Project on the machine with IIS 6. If your IIS 6 machine is on a different machine, you can skip this step. We can deploy the site to the machine later.
After you create the project, right click the project and select Properties. The project properties editor will open up. Select the Web tab and select Use IIS Web Server. Click on the image for a full size view.
Project Properties Editor
In the project URL, I gave it a virtual application name of Iis6DemoWeb and then checked Create Virtual Directory. A dialog box should appear and you should now have an IIS virtual application (note this is different than a virtual directory, as indicated by the gear looking icon) under your Default Web Site.
IIS 6 Virtual Web Application

Using a URL File Extensions

When you run the ASP.NET MVC installer, it will set up an ISAPI mapping in IIS 6 to map the .mvc extension to the aspnet_isapi.dll. This is necessary in order for IIS to hand off requests using the .mvc file extension to ASP.NET.
If you’re planning to use extension-less URLs, you can skip this section, but it may be useful to read anyways as it has some information you’ll need to know when setting up extension-less URLs.

Mapping .mvc to ASP.NET

If you plan to use the .mvc URL extension, and are going to deploy to IIS 6 on a machine that does not have ASP.NET MVC installed, you’ll need to create this mapping by performing the following steps.
One nice benefit of using the .aspx extension instead of .mvc is that you don’t have to worry about mapping the .aspx extension. It should already be mapped assuming you have ASP.NET installed properly on the machine.
For the rest of you, start by right clicking on the Virtual Application node (IIS6DemoWeb in this case) and select Properties. You should see the following dialog.
Website Properties
Make sure you’re on the Virtual Directory tab and select Configuration. Note that you can also choose to make this change on the root website, in which case the tab you’re looking for is Home Directory not Virtual Directory.
This will bring up the Application Configuration dialog which displays a list of ISAPI mappings. Scroll down to see if .mvc is in the list.
application mappings
In the screenshot, you can see that .mvc is in the list. If it is in the list on your machine, you can skip ahead to the next section. If it’s not in the list for you, let’s add it to the list. You’re going to need to know the path to the aspnet_isapi.dll first. On my machine, it is:
c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll
It might differ on your machine. One easy way to find out is to find the .aspx extension in the list and double click it to bring up the mapping dialog.
extension mapping
Now you can copy the path in the Executable text box to your clipboard. This is the path you’ll want to map .mvc to.
Click Cancel to go back to the Application Configuration dialog and then click Addwhich will bring up an empty Add/Edit Application Extension Mapping dialog.
Fill in the fields with the exact same values as you saw for .aspx, except the extension should be “.mvc” without the quotes. Click OK and you’re done with the mapping.

Specifying Routes with an Extension

Before we run the application, we need to update the default routes to look for the file extension we chose, whether it be .mvc or .aspx extension. Here is theRegisterRoutes method in my Global.asax.cs file using the .mvc extension. If you want to use the .aspx extension, just replace {controller}.mvc with{controller}.aspx.
public static void RegisterRoutes(RouteCollection routes)
{
  routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

  routes.MapRoute(
    "Default",
    "{controller}.mvc/{action}/{id}",
    new { action = "Index", id = "" }
  );

  routes.MapRoute(
    "Root",
    "",
    new { controller = "Home", action = "Index", id = "" }
  );
}
Note that because the second route, “Default”, has a literal extension as part of the URL segment, it cannot match a request for the application root. That’s why I have a third route named “Root” which can match requests for the application root.
Now, I can hit CTRL+F5 (or browse my website) and I should see the following home page.
Home Page
And about page.
About Page
Notice that the URLs contain the .mvc extension.

Uh oh, Houston! We have a problem

Of course, you’re going to want to be able to navigate to the web root for your project. Notice what happens when you navigate to /Iis6DemoWeb.
Root Home Page
This is a bug in the Default.aspx.cs file included with our default template which I discovered as I was writing this walkthrough. We’ll fix it right away, but I can provide the fix here as it’s insanely easy.
Note: If you received a File Not Found error when visiting the root, then you might not have Default.aspx mapped as a default document. Follow these steps to add Default.aspx as a default document.
As I’ve written before, this file is necessary for IIS 6, IIS 7 Classic Mode, and pre SP1 Cassini, but not IIS 7 Integrated. So if you’re using Cassini with Visual Studio 2008 SP1 and deploying to IIS 7 Integrated, you can delete Default.aspx and its sub-files.
In the meanwhile, the fix is to make the following change.
Change:
HttpContext.Current.RewritePath(Request.ApplicationPath);
To
HttpContext.Current.RewritePath(Request.ApplicationPath, false);
If you created your website in the IIS root rather than a virtual application, you would never have noticed this issue. But in the virtual application, the URL to the stylesheet rendered contained the virtual application name, when it shouldn’t. Changing the second argument to false fixes this.

IIS6 Extension-less URLs

Ok, now we’re ready to try this with extension-less URLs using the infamous “Star mapping” or “Wildcard mapping” feature of IIS 6. I say infamous because there is a lot of concern over the performance implications of doing this. Of course, you should measure the performance of your site for yourself to determine if it is really a problem.
The first step is to go back to the Application Configuration Properties dialog like we did when configuring the .mvc ISAPI mapping (see, I told you that information might come in useful later).
application mappings
Next to the Wildcard application maps section, click the Insert… button.
wildcard extension mapping
This brings up the wildcard application mapping dialog. Enter the path to theaspnet_isapi.dll. You can follow the trick we mentioned earlier for getting this path.
Don’t forget to uncheck the Verify that file exists checkbox! This is one of the most common mistakes people make.
If you’ve been following along everything in this post, you’ll need to go back and reset the routes in your Global.asax.cs file to the default routes. You no longer need the .mvc file extension in the routes. At this point, you can also removeDefault.aspx if you’d like. It’s not needed.
Now when you browse your site, your URLs will not have a file extension as you can see in the following screenshots.
Home page without extension
About page without extension

Final Tips

One thing to understand is that an ASP.NET project is scoped to the Website or Virtual Application in which it resides. For example, in the example I have here, we pointed a Virtual Application named IIS6DemoWeb to the directory containing my ASP.NET MVC web application.
Thus, only requests for that virtual application will be handled by my web application. I cannot make a request for http://localhost/ in this case and expect it to be handled by my application. Nor can I expect routing in this application to handle requests for another root directory such as http://localhost/not-my-app/.
This might seem like an obvious thing to say, but I know it trips some people up. Also, in the example I did here, I used a virtual application for demonstration purposes. It’s very easy to point a root Website in IIS to my application and run it in http://localhost/ rather than a virtual application. This is not a problem. I hope you found this helpful.

Reset root password Oracle DB

sqlplus /nolog
connect / as sysdba
ALTER USER sys IDENTIFIED BY "new_password";

Tuesday, July 16, 2013

Chuyển đổi chuỗi html chứa các thẻ table thành DataTable hoặc DataSet

Trong bài viết này tôi giới thiệu các bạn một Class khá hay có tác dụng chuyển đổi chuỗi html chứa các thẻ table thành DataTable hoặc DataSet - Convert Html Table Tag to Datatable or DataSet. DataTable, DataSet, Html, Table, Html Table, Convert,
Đây là một class tôi nghĩ khá hay mà bạn có thể dùng vào nhiều mục dích khác nhau, Ví dụ đơn giản nhất đó là bạn muốn bóc tách nội dung của 1 trang web mà source nguồn có chứa các thẻ html thành DataTable hoặc DataSet. Ví dụ như trang http://vov.vn/Media/List.aspx?catid=49 Khi view source lên bạn sẽ thấy từ dòng 351 đến dòng 616 là nội dung thẻ Table chứa danh sách các media đọc chuyện Nhật ký Đặng Thùy Trâm. Bạn muốn bóc tách và đưa các media đó về website của bạn? việc sử dụng Class chuyển đổi chuỗi html chứa các thẻ table thành DataTable hoặc DataSet sẽ nhanh và hiệu quả.
Dưới đây là toàn bộ nội dung của Class này. Tôi đã ghi tất cả các chú thích cho các hàm tương ứng. Tôi không tách từng hàm ra nữa.
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Net;
using System.IO;
using System.Xml;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
/// 
/// Summary description for HtmlTableParser
/// 
public class HtmlTableParser
{
    private const RegexOptions ExpressionOptions = RegexOptions.Singleline | RegexOptions.Multiline | RegexOptions.IgnoreCase;

    private const string CommentPattern = "";
    private const string TablePattern = "]*>(.*?)
"; private const string HeaderPattern = "]*>(.*?)"; private const string RowPattern = " ]*>(.*?) "; private const string CellPattern = "]*>(.*?)"; /// /// Một chuỗi html có nhiều bảng, phân tích và đưa các bảng này thành DataSet /// /// Một chuỗi HTML bao gồm nhiều bảng /// Một DataSet có chứa một DataTable cho mỗi bảng HTML trong chuỗi đầu vào public DataSet ParseDataSet(string html) { DataSet dataSet = new DataSet(); MatchCollection tableMatches = Regex.Matches( WithoutComments(html), TablePattern, ExpressionOptions); foreach (Match tableMatch in tableMatches) { dataSet.Tables.Add(ParseTable(tableMatch.Value)); } return dataSet; } /// /// Chuỗi HTML có chứa một bảng duy nhất, phân tích bảng thành một DataTable. /// /// Chuỗi HTML có chứa một bảng duy nhất /// Một DataTable public DataTable ParseTable(string tableHtml) { string tableHtmlWithoutComments = WithoutComments(tableHtml); DataTable dataTable = new DataTable(); MatchCollection rowMatches = Regex.Matches( tableHtmlWithoutComments, RowPattern, ExpressionOptions); dataTable.Columns.AddRange(tableHtmlWithoutComments.Contains(" /// Loại bỏ các comment của chuỗi html ///
/// Chuỗi html có chú thích /// Trả về chuỗi html đã được loại hết chú thích private string WithoutComments(string html) { return Regex.Replace(html, CommentPattern, string.Empty, ExpressionOptions); } /// /// Thêm 1 dòng vào DataTable sử dụng MatchCollection /// /// Tập hợp các dòng thêm vào DataTable /// Một DataTable đã được thêm các dòng private void ParseRows(MatchCollection rowMatches, DataTable dataTable) { foreach (Match rowMatch in rowMatches) { // Chỉ sử dụng các hàng không phải tiêu đề bảng if (!rowMatch.Value.Contains(" /// Chuỗi có chứa một bảng HTML, phân tích các tiêu đề tạo ra các DataColumns của một DataTable. /// /// Một chuỗi HTML có chứa một bảng HTML /// Các DataColumns của một DataTable private DataColumn[] ParseColumns(string tableHtml) { MatchCollection headerMatches = Regex.Matches( tableHtml, HeaderPattern, ExpressionOptions); return (from Match headerMatch in headerMatches select new DataColumn(headerMatch.Groups[1].ToString())).ToArray(); } /// /// Phân tích dữ liệu không phải tiêu đề đưa vào các Columns /// /// Các hàng trong bảng HTML chúng ta tạo ra các cột /// Tập hợp các DataColumns dựa trên số lượng celss trong hàng đầu tiên của bảng đầu vào HTML private DataColumn[] GenerateColumns(MatchCollection rowMatches) { int columnCount = Regex.Matches( rowMatches[0].ToString(), CellPattern, ExpressionOptions).Count; return (from index in Enumerable.Range(0, columnCount) select new DataColumn("Column " + Convert.ToString(index))).ToArray(); } public HtmlTableParser() { // // TODO: Add constructor logic here // } }

Cắt n ký tự đầu tiên của một chuỗi với C#

 public static string CatChuoi(this string s, int length)
    {
        if (String.IsNullOrEmpty(s))
            throw new ArgumentNullException(s);
        var words = s.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
        if (words[0].Length > length)
            throw new ArgumentException("Từ đầu tiên dài hơn chuỗi cần cắt");
        var sb = new StringBuilder();
        foreach (var word in words)
        {
            if ((sb + word).Length > length)
                return string.Format("{0}...", sb.ToString().TrimEnd(' '));
            sb.Append(word + " ");
        }
        return string.Format("{0}...", sb.ToString().TrimEnd(' '));
    }

Giải pháp Session timeout trong ASP.NET

Session timeout Là khoảng thời gian lớn nhất có thể giữa hai lần user request lên server mà session của user chưa bị hủy. Vấn đề thường gặp là Session hay bị mất khi đang xử lý thông tin trước khi Submit form. Bài viết này xin giới thiệu một giải pháp cho vấn đề session timeout trong asp.net

1. Session timeout là gì?

Là khoảng thời gian lớn nhất có thể giữa hai lần user request lên server mà session của user chưa bị hủy. Nói một cách đơn giản hơn, giả sử giá trị timeout này là 30′, thì cứ trong 30′, nếu user không gửi một request nào lên server thì session của user đó sẽ không còn hiệu lực.
Trong ASP.NET, session timeout mặc định là 20′. Có nhiều cách để thay đổi giá trị này, đơn giản nhất là thêm một dòng trong web.config




2. Đặt timeout bao nhiêu là hợp lý?

Giá trị mặc định của nó là 20′, tuy nhiên trong một số trường hợp bạn muốn session tồn tại lâu hơn. Ví dụ một ứng dụng web cho phép người dùng soạn thảo nội dung trực tiếp trên trình duyệt. Bạn không muốn session kết thúc trước khi người dùng soạn thảo xong văn bản, vì thế bạn thiết lập timeout bằng một số rất lớn. Điều này không thực sự ổn vì nó sẽ tốn rất nhiều bộ nhớ của server dành cho session của những người dùng không còn trên website của bạn.

3. Heart beat pattern

Có một giải pháp cho vấn đề này: Thiết lập một giá trị session timeout nhỏ. Đồng thời, phía client sẽ “âm thầm” gửi các request nhỏ, thường xuyên đến server để báo cho server biết nó vẫn còn “sống”. Do đó bạn sẽ không bị tốn bộ nhớ một cách vô ích cho session của những người dùng không còn trên trang. Phương pháp này được biết dưới cái tên Heartbeat design pattern.
Tôi thực hiện điều này trong ASP.NET một cách đơn giản như sau:
+ Thiết lập một giá trị nhỏ cho session timeout (giả sử là 5′)
+ Tạo trang KeepAlive.ashx để nhận request thường xuyên từ client. Trang này không cần làm gì cũng được.
+ Thêm đoạn code javascript sau vào trang bạn muốn thực hiện. Tốt nhất là đặt chúng trong các trang master page

function heartBeat() {
    $.get("KeepAlive.ashx?", function (data) {});
}
$(function () {
    setInterval("heartBeat()", 1000 * 30); // 30s gửi request một lần
});

Tuesday, July 9, 2013

ASP.NET MVC on IIS 6 Walkthrough

I’ve seen a lot of reports where people have trouble getting ASP.NET MVC up and running on IIS 6. Sometimes the problem is a very minor misconfiguration, sometimes it’s a misunderstanding of how IIS 6 works.
In this post, I want to provide a definitive guide to getting ASP.NET MVC running on IIS 6. I will walk through using the .mvc or .aspx file extension for URLs first, then I will walkthrough using extension-less URLs.
If you’re running into problems with IIS 6 and ASP.NET MVC, I recommend trying to walk through all the steps in this post, even if you’re not interested in using the.mvc or .aspx mapping. Some of the lessons learned here have more to do with how ASP.NET itself works with IIS 6 than anything specific to ASP.NET MVC.

Initial Setup

To make this easy, start Visual Studio and create a new ASP.NET MVC Web Application Project on the machine with IIS 6. If your IIS 6 machine is on a different machine, you can skip this step. We can deploy the site to the machine later.
After you create the project, right click the project and select Properties. The project properties editor will open up. Select the Web tab and select Use IIS Web Server. Click on the image for a full size view.
Project Properties Editor
In the project URL, I gave it a virtual application name of Iis6DemoWeb and then checked Create Virtual Directory. A dialog box should appear and you should now have an IIS virtual application (note this is different than a virtual directory, as indicated by the gear looking icon) under your Default Web Site.
IIS 6 Virtual Web Application

Using a URL File Extensions

When you run the ASP.NET MVC installer, it will set up an ISAPI mapping in IIS 6 to map the .mvc extension to the aspnet_isapi.dll. This is necessary in order for IIS to hand off requests using the .mvc file extension to ASP.NET.
If you’re planning to use extension-less URLs, you can skip this section, but it may be useful to read anyways as it has some information you’ll need to know when setting up extension-less URLs.

Mapping .mvc to ASP.NET

If you plan to use the .mvc URL extension, and are going to deploy to IIS 6 on a machine that does not have ASP.NET MVC installed, you’ll need to create this mapping by performing the following steps.
One nice benefit of using the .aspx extension instead of .mvc is that you don’t have to worry about mapping the .aspx extension. It should already be mapped assuming you have ASP.NET installed properly on the machine.
For the rest of you, start by right clicking on the Virtual Application node (IIS6DemoWeb in this case) and select Properties. You should see the following dialog.
Website Properties
Make sure you’re on the Virtual Directory tab and select Configuration. Note that you can also choose to make this change on the root website, in which case the tab you’re looking for is Home Directory not Virtual Directory.
This will bring up the Application Configuration dialog which displays a list of ISAPI mappings. Scroll down to see if .mvc is in the list.
application mappings
In the screenshot, you can see that .mvc is in the list. If it is in the list on your machine, you can skip ahead to the next section. If it’s not in the list for you, let’s add it to the list. You’re going to need to know the path to the aspnet_isapi.dll first. On my machine, it is:
c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll
It might differ on your machine. One easy way to find out is to find the .aspx extension in the list and double click it to bring up the mapping dialog.
extension mapping
Now you can copy the path in the Executable text box to your clipboard. This is the path you’ll want to map .mvc to.
Click Cancel to go back to the Application Configuration dialog and then click Addwhich will bring up an empty Add/Edit Application Extension Mapping dialog.
Fill in the fields with the exact same values as you saw for .aspx, except the extension should be “.mvc” without the quotes. Click OK and you’re done with the mapping.

Specifying Routes with an Extension

Before we run the application, we need to update the default routes to look for the file extension we chose, whether it be .mvc or .aspx extension. Here is theRegisterRoutes method in my Global.asax.cs file using the .mvc extension. If you want to use the .aspx extension, just replace {controller}.mvc with{controller}.aspx.
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default",
"{controller}.mvc/{action}/{id}",
new { action = "Index", id = "" }
);
routes.MapRoute(
"Root",
"",
new { controller = "Home", action = "Index", id = "" }
);
}
Note that because the second route, “Default”, has a literal extension as part of the URL segment, it cannot match a request for the application root. That’s why I have a third route named “Root” which can match requests for the application root.
Now, I can hit CTRL+F5 (or browse my website) and I should see the following home page.
Home Page
And about page.
About Page
Notice that the URLs contain the .mvc extension.

Uh oh, Houston! We have a problem

Of course, you’re going to want to be able to navigate to the web root for your project. Notice what happens when you navigate to /Iis6DemoWeb.
Root Home Page
This is a bug in the Default.aspx.cs file included with our default template which I discovered as I was writing this walkthrough. We’ll fix it right away, but I can provide the fix here as it’s insanely easy.
Note: If you received a File Not Found error when visiting the root, then you might not have Default.aspx mapped as a default document. Follow these steps to add Default.aspx as a default document.
As I’ve written before, this file is necessary for IIS 6, IIS 7 Classic Mode, and pre SP1 Cassini, but not IIS 7 Integrated. So if you’re using Cassini with Visual Studio 2008 SP1 and deploying to IIS 7 Integrated, you can delete Default.aspx and its sub-files.
In the meanwhile, the fix is to make the following change.
Change:
HttpContext.Current.RewritePath(Request.ApplicationPath);
To
HttpContext.Current.RewritePath(Request.ApplicationPath, false);
If you created your website in the IIS root rather than a virtual application, you would never have noticed this issue. But in the virtual application, the URL to the stylesheet rendered contained the virtual application name, when it shouldn’t. Changing the second argument to false fixes this.

IIS6 Extension-less URLs

Ok, now we’re ready to try this with extension-less URLs using the infamous “Star mapping” or “Wildcard mapping” feature of IIS 6. I say infamous because there is a lot of concern over the performance implications of doing this. Of course, you should measure the performance of your site for yourself to determine if it is really a problem.
The first step is to go back to the Application Configuration Properties dialog like we did when configuring the .mvc ISAPI mapping (see, I told you that information might come in useful later).
application mappings
Next to the Wildcard application maps section, click the Insert… button.
wildcard extension mapping
This brings up the wildcard application mapping dialog. Enter the path to theaspnet_isapi.dll. You can follow the trick we mentioned earlier for getting this path.
Don’t forget to uncheck the Verify that file exists checkbox! This is one of the most common mistakes people make.
If you’ve been following along everything in this post, you’ll need to go back and reset the routes in your Global.asax.cs file to the default routes. You no longer need the .mvc file extension in the routes. At this point, you can also removeDefault.aspx if you’d like. It’s not needed.
Now when you browse your site, your URLs will not have a file extension as you can see in the following screenshots.
Home page without extension
About page without extension

Final Tips

One thing to understand is that an ASP.NET project is scoped to the Website or Virtual Application in which it resides. For example, in the example I have here, we pointed a Virtual Application named IIS6DemoWeb to the directory containing my ASP.NET MVC web application.
Thus, only requests for that virtual application will be handled by my web application. I cannot make a request for http://localhost/ in this case and expect it to be handled by my application. Nor can I expect routing in this application to handle requests for another root directory such as http://localhost/not-my-app/.
This might seem like an obvious thing to say, but I know it trips some people up. Also, in the example I did here, I used a virtual application for demonstration purposes. It’s very easy to point a root Website in IIS to my application and run it in http://localhost/ rather than a virtual application. This is not a problem. I hope you found this helpful.

Wednesday, May 29, 2013

Percona MySQL installation tutorial


How to install

  • Install the Percona repository
 rpm -Uhv http://www.percona.com/downloads/percona-release/percona-release-0.0-1.$(uname -i).rpm
  • If the above RPM repo is not found you can check for up-to-date documentation here
 http://www.percona.com/docs/wiki/repositories:yum
  • Check the current MySQL version installed on the server
 root@grumpy [~]# mysql -V
 mysql  Ver 14.12 Distrib 5.0.92, for unknown-linux-gnu (x86_64) using readline 5.1
 root@grumpy [~]# 
  • Stop mysql server on the machine. Make sure that guardian will not restart it after stop!
 root@grumpy [~]# if [ -d /svcstop ]; then touch /svcstop/mysql; fi
 root@grumpy [~]# /etc/init.d/mysql stop
 Shutting down MySQL.                                       [  OK  ]
 root@grumpy [~]# 
  • Backup the raw files of mysql
 root@grumpy [~]# cp -a /var/lib/mysql /var/lib/mysql.backup
 root@grumpy [~]# 
  • Generate a list of your current databases
 root@grumpy [~]# mysql -A -sN -e "show databases" > active.db.list.log
  • Remove MySQL-server installed on this machine. While removing it with yum make sure that it will not remove OTHER critical system packages. If it does so use rpm -e --nodeps instead!
 root@grumpy [~]# rpm -qa | grep -i "mysql.*server"
 MySQL-server-5.0.92-0.glibc23
 root@grumpy [~]# yum remove MySQL-server-5.0.92-0.glibc23
  • Make sure to install Percona with the same ${major}.${minor} version as the old MySQL version. Use the following command to install PerconaSQL server. Disable excludes are added because of cPanel /etc/yum.conf config.
 yum --disableexcludes=main install Percona-SQL-server-SET-CORRECT-VERSION-HERE
  • Monitor closely the response of the installation process for any errors
  • Usually MySQL will be automatically started after the above yum install command. If not make sure to start it.
  • Try to connect to the MySQL server
 root@grumpy [~]# mysql -A
  • Check the mysql error log for any errors very carefully!
 root@sgded-bizserver [~]# tail -f /var/lib/mysql/$(hostname).err
  • Make sure that all clients databases are present:
 mysql -A -sN -e "show databases" > new.db.list.log
 for dbname in $(> /dev/null ); then
               echo "Database $dbname is missing from show databases"
       fi
 done
  • Enable User Statistics in /etc/my.cnf
 sed -i '/userstat_running/D' /etc/my.cnf && echo "userstat_running=1" >> /etc/my.cnf && /etc/init.d/mysql restart
Keep in mind that the userstat_running variable should be after [mysqld] definition and before any other [] definitions.
  • Make sure that the user statistics are enabled for the MySQL server
 root@grumpy [~]# mysql -e 'show variables like "userstat_running"'
 +------------------+-------+
 | Variable_name    | Value |
 +------------------+-------+
 | userstat_running | ON    | 
 +------------------+-------+
If in the above output you see OFF, this means that the userstat_running variable is in the wrong place in /etc/my.cnf.
  • You can verify that the statistics are working by executing the following command:
 root@grumpy [~]# mysql -A -sN information_schema -e "select * from user_statistics;"
  • Enable CPUstats for percona by executing:
 /usr/local/1h/bin/detect_mysql.sh
  • If you are using cPanel - In order to prevent cPanel upgrades from automatically restarting MySQL create the following files:
touch /etc/mysqldisable
touch /etc/mysqlupdisable
  • Remove guardian lock file
 root@grumpy [~]# if [ -f /svcstop/mysql ]; then rm -f /svcstop/mysql; fi

How to revert

  • Stop MySQL-Percona
  • Remove userstat_running from /etc/my.cnf
  • Install the same version of MySQL as percona was
  • Start MySQL