Monday, September 29, 2008

Clone Controls, C# Sample

This post explains about creating clone objects using C#.

For example, you may need a grid with some standard design to repeat dynamically. You can use the below code to create the clone of the required controls or objects.

private object CloneControls(object o)
{
Type type = o.GetType();
PropertyInfo[] properties = type.GetProperties();
Object retObject = type.InvokeMember("", System.Reflection.BindingFlags.CreateInstance, null, o, null);
foreach (PropertyInfo propertyInfo in properties)
{
if (propertyInfo.CanWrite)
{
propertyInfo.SetValue(retObject, propertyInfo.GetValue(o, null), null);
}
}
return retObject;
}

Friday, September 26, 2008

System.Web.Extensions 3.6.0.0 change in .Net 3.5 Framework Service Pack 1 Release

Reference: www.asp.net

The following steps describe changes that you must make in the Web.config file in order to change a Dynamic Data Web site created with the December CTP release to work with the .NET 3.5 Service Pack 1 release.
  1. Make sure that you have uninstalled the software described in
    Compatibility with Previous Releases

  2. Make sure you have installed the combined Visual Studio 2008 and .NET Framework
    3.5 Service Pack 1 release.

  3. Start Visual Studio 2008 Service Pack 1 and open the existing Dynamic Data application.

  4. Change all references of System.Web.Extensions,
    Version=3.6.0.0
    to System.Web.Extensions, Version=3.5.0.0.

  5. Remove the following configuration section:
    <section name="dynamicData" type="System.Web.DynamicData.DynamicDataControlsSection"
    requirePermission="false" allowDefinition="MachineToApplication"/>

  6. In the <assemblies> element, add the
    following elements:
    <add assembly="System.Web.Abstractions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    <add assembly="System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    <add assembly="System.ComponentModel.DataAnnotations, Version=3.5.0.0, Culture=neutral,
    PublicKeyToken=31BF3856AD364E35"/> <add assembly="System.Web.DynamicData,
    Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
  7. In the <assemblies> element, remove
    the following item:
    <add assembly="System.Web.DynamicData, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
  8. In the <controls> section, remove
    the following elements:
    <add tagPrefix="asp" namespace="System.Web.DynamicData" assembly="System.Web.Extensions,
    Version=3.6.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> <add
    tagPrefix="asp" tagName="DynamicFilter" src="~/App_Shared/DynamicDataFields/FilterUserControl.ascx"/>
  9. In the <controls> section, add the
    following element:
    <add tagPrefix="asp" namespace="System.Web.DynamicData" assembly="System.Web.DynamicData,
    Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
  10. In the <httpModules> section, remove
    the following elements:
    <add name="DynamicDataModule" type="System.Web.DynamicData.DynamicDataHttpModule,
    System.Web.Extensions, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    <add name="UrlRoutingModule" type="System.Web.Mvc.UrlRoutingModule, System.Web.Extensions,
    Version=3.6.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
  11. In the <httpModules> section, add
    the following entry:
    <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing,Version=3.5.0.0,
    Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

  12. Remove the <dynamicData> configuration
    section.

  13. In the <runtime> section, replace the following section:
    <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
    <assemblyIdentity name="System.Web.Extensions" publicKeyToken="31bf3856ad364e35"/>
    <bindingRedirect oldVersion="1.0.0.0-3.5.0.0" newVersion="3.6.0.0"/>
    </dependentAssembly>
    <dependentAssembly>
    <assemblyIdentity name="System.Web.Extensions.Design" publicKeyToken="31bf3856ad364e35"/>
    <bindingRedirect oldVersion="1.0.0.0-3.5.0.0" newVersion="3.6.0.0"/>
    </dependentAssembly>
    </assemblyBinding>
    </runtime>

    With the following section:
    <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
    <assemblyIdentity name="System.Web.Extensions" publicKeyToken="31bf3856ad364e35"/>
    <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>
    </dependentAssembly>
    <dependentAssembly>
    <assemblyIdentity name="System.Web.Extensions.Design" publicKeyToken="31bf3856ad364e35"/>
    <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>
    </dependentAssembly>
    </assemblyBinding>
    </runtime>


Show your Skype and Yahoo Online Status in your website


This post will explain about how to show the skype and yahoo online status in your website.

Skype Online Status in Website:

Include the following script in your page:

And add the following tag in your page:

<a onclick="return skypeCheck();" href="skype:{0}?call">
<img id="Img" src="http://mystatus.skype.com/bigclassic/{0}" border="0" runat="server" /></a>

In the above tag, {0} represents your loginid in skype. Ex.: prasadvemala

Check my skype status below:

prasadvemala

If the status is not showing you in Online when you are, go to skype Options -> Privacy settings and make sure the settings 'Allow my status to be shown on the web' is checked.

Yahoo Messenger Online Status in Website:

Add the following tag in your page:

<a href="http://edit.yahoo.com/config/send_webmesg?.target={0}&.src=pg"><img src="http://opi.yahoo.com/online?u={0}&m=g&t=2" /></a>

In the above tag, {0} represents your loginid in yahoo. Ex.: prasadvemala

Check my Yahoo status below:

prasadvemala


Thursday, September 25, 2008

Sign In Using Google Account

This post explains about allowing your website users to login using google account without registering with your website. Thus it makes your website users to avoid multiple registration and also remembering multiple login credentials.

The below picture shows you the steps involved in the signin using google process:

Authentication Process
Prerequisites:

First you need to register your website with google for secured communication and transfer of users from your website to google for authentication. Use the below link to register your website with google:


Once you have registered your website with the google using the steps stated in the above link, the users of your website will be redirected to your website from google without a warning.

You can go to the below URL directly to signup with google and manage the domains:


You may require the following dlls for implementing this sample code:
  • Google.GData.Client.dll

  • Google.GData.Contacts.dll

  • Google.GData.Extensions.dll

The above dlls can be downloaded from the following URL:

Lets see the example for this implementation:

Create a web page named "GoogleSignIn.aspx". Consider this as the login page of your website.

Put the below Code in your aspx page:
<asp:HyperLink ID="GotoAuthSubLink" runat="server" />

Put the below code in page load of the page:
//Initially keep the hyperlink as visible false.
GotoAuthSubLink.Visible = false;

//This portion is executed when the users comes back without logging out
if (Session["token"] != null)
{
GetUserDetails();
}
//This portion is executed when the users are redirected to your website from the google after the authentication is success. When the users redirected to your website from google, you'll get a token as a querystring which acts as a authorized token. Then this has to be sent to google to get access token, which is used to get the user details like name, emailid, etc.,
else if (Request.QueryString["token"] != null)
{
String token = Request.QueryString["token"];
Session["token"] = AuthSubUtil.exchangeForSessionToken(token, null).ToString();
Response.Redirect(Request.Url.AbsolutePath, true);
}
//This Part executes when the user comes to your website for the first time and before the user is directed to google for authentication.
else //no auth data, print link
{
GotoAuthSubLink.Text = "Login to your Google Account";
GotoAuthSubLink.Visible = true;
//The parameters for the method getRequestUrl are the target page to which the user has to be redirected once the user is authenticated, google url, secure, session
GotoAuthSubLink.NavigateUrl = AuthSubUtil.getRequestUrl(Request.Url.ToString(),
"http://www.google.com/m8/feeds/contacts", false, true);
}

void GetUserDetails()
{
GAuthSubRequestFactory authFactory = new GAuthSubRequestFactory("mywebsite", "mywebsite");
authFactory.Token = (String)Session["token"];
Google.GData.Contacts.ContactsService service = new Google.GData.Contacts.ContactsService(authFactory.ApplicationName);
service.RequestFactory = authFactory;
Google.GData.Contacts.ContactsQuery query = new Google.GData.Contacts.ContactsQuery(Google.GData.Contacts.ContactsQuery.CreateContactsUri("default"));
try
{
Google.GData.Contacts.ContactsFeed feed = service.Query(query);
Response.Write(feed.Authors[0].Name);
Response.Write(feed.Authors[0].Email);
foreach (Google.GData.Contacts.ContactEntry entry in feed.Entries)
{
Response.Write("\t" + entry.Title.Text);
foreach (EMail email in entry.Emails)
{
Response.Write("\t" + email.Address);
}
}
}
catch (GDataRequestException gdre)
{
HttpWebResponse response = (HttpWebResponse)gdre.Response;
//bad auth token, clear session and refresh the page
if (response.StatusCode == HttpStatusCode.Unauthorized)
{
Session.Clear();
Response.Redirect(Request.Url.AbsolutePath, true);
}
else
{
Response.Write("Error processing request: " + gdre.ToString());
}
}
}

After you have done with the above steps, you need to map the email-id with the user suggested name.

The good example of this implemenation is zoho. Look at http://www.zoho.com/, which uses the concept of signin using google.