Wednesday, April 27, 2011

Quick Login Extension - The simple and automatic Google (Apps) Account switcher for Google Chrome


I've been using this extension for quite a long time and have to say that this one rocks! I've almost forgot my passwords for all of my Google accounts (which is not actually an advantage, i guess) as i have this extension installed on my Google Chrome

I have around 8 Google accounts for a variety of purposes and i was finding this very time consuming to type in all the details whenever i have to login OR to switch between my Google accounts. Now, with this extension, i can just click any of the names, and it just takes me directly into my account. I can also switch between my Google accounts by just logging out in which the extension opens up the configured accounts, and a click again takes me in to the desired account.

Moreover, if i landed upon any of the google login pages, it shows up the assistant automatically. Currently, this extension supports up to 10 accounts and i would like to keep it in posts so that others can find and use it. And hey.. it works with Google Apps Accounts too. Enjoy!

This extension is available here
https://chrome.google.com/webstore/detail/cbgngpehipfmfmpjmhonhacgbkjpdidp

The Facebook page for this extension is at
http://www.facebook.com/quick.access.gaccounts


Friday, April 1, 2011

Gmail Motion is Google's April Fool 2011?

I just saw Gmail Motion and it looks like a very unusual feature for Google to come up with. Considering that today is April 1st, this is a best candidate for April Fool Joke for this year. They do this all the time!

Don't fall for it!


Sunday, December 12, 2010

Pass and Use variables in ASP.net server to the client HTML or JavaScript code - Multiple ways

Any public variables available during the page load (page_load event) is usable as variables in the HTML code. Below are the multiple ways of using them.

Using ASP.net variables:
public partial class VariableTest : System.Web.UI.Page
{
    public string url = "http://www.google.com";
    protected void Page_Load(object sender, EventArgs e)
    {
       
    }
}
HTML Usage:
<a href="<%= url %>">click here</a>
Using Sessions:

These session variables might have loaded at any stage of your application. Even global.asax loading will do. Just make sure that they are available during page load.
protected void Page_Load(object sender, EventArgs e)
    {
        Session["newurl"] = "http://www.google.com";
    }
HTML Usage:
<a href="<%= Session["newURL"] %>">Click here</a>
Using Web.Config:
    Web.config file has the variable value as mentioned below.
<appSettings>
    <add key="newURL" value="http://www.google.com"/>
</appSettings>
HTML Usage:
<a href="<%= ConfigurationManager.AppSettings["newURL"] %>">Click Here</a>
Make sure that the namepsaces are referenced from your page. Otherwise you will have to change like System.Configuration.ConfigurationManager.AppSettings["newURL"]

Using the Variables in JavaScript
     Basically, all the above mentioned usages work like a string replace. So, you can even use it in javascript codes as shown below.
<a href="#" onclick="javascript:alert('<%= urls %>');return false;">Click here</a>
Using these variables in Server controls.
     Controls with server rendering enabled (runat="server") will not work using the methods mentioned above. Use Page.DataBind() to do the trick for you. Make sure that you are using <%# %> in this case

Server Code:
public partial class VariableTest : System.Web.UI.Page
{
    public string newurl = "http://www.google.com";
    protected void Page_Load(object sender, EventArgs e)
    {
        Page.DataBind();
    }
}

Designer Code:
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="<%# newurl %>">HyperLink</asp:HyperLink>
OR
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="<%# this.newurl %>">HyperLink</asp:HyperLink>


Wednesday, December 8, 2010

How to do a 301 redirect in ASP.net for permanently moved resources - Global.asax code changes

If you are here, you might already be knowing that 301 redirect is the standard way of telling your clients (browsers, usually) that a server resource or a page has been permanently moved to a new location. Since most search engines respect this code, they will make sure that your 301 redirects are duly noted in their indexes which results in accurate search results.

Here is one raw way of implementing this, using Global Application Class (Global.asax) file.

Pre-requisites
I'm assuming that you have a Global.asax file  in your specific ASP.net project. If don't, add it as a New Item. It will have already a place to handle Application level errors. The below code is the code, where you're going to implement the changes.

 void Application_Error(object sender, EventArgs e)
    {
        // Code that runs when an unhandled error occurs

    }
The Logic:
The idea is to trap the 404 error (this will occur since the requested page does not exists) and provide appropriate 301 redirect request as the output. The below code does just that. Refer inline comments for more information on what each line of code means.

The Sample Code:

void Application_Error(object sender, EventArgs e) 
    { 
        // Code that runs when an unhandled error occurs
        // retrieve the last server error
        HttpException he = (HttpException)Server.GetLastError();
        // check for 404 error
        if (he.GetHttpCode() == 404)
        {
            // implement the logic to decide whether redirect is needed
            if (Request.RawUrl.ToLower().Contains("oldpage.aspx"))
            {
                Server.ClearError(); // clear the existing server error, good to have for additional processing
                Response.Clear(); //clears the response cache, if some information already exists
                Response.Status = "301 Moved Permanently"; // set the 301 status header
                Response.AddHeader("Location", "newpage.aspx"); // set the redirect location
                Response.End();
            }
            
        }
    }

For simplicity sake, additional checks are avoided in the above code.

If more flexibility and control is needed, look for a good URL rewriter for ASP.net.

In case, if you're wondering what a Response.Redirect does, it's just a 302 redirect that says that the resource is found at another location, which is treated as a temporary redirect. For more information, refer the HTTP Status Codes at http://en.wikipedia.org/wiki/List_of_HTTP_status_codes