Archive for March, 2009

  • Mar
  • 21
  • 2009

Facebook Connect and Asp.net

Tags: , , | View: 2,287 | Comments:

With Facebook Connect, you are able to integrate the Facebook Platform with your own web application. Facebook Connect does not provide many functions as Facebook itself for now but provides some very nice functions which can add values for your web applications. I am not going to mention about developing Facebook Connect application from scratch, you can find more about this from Facebook’s development pages.

What I am going to share is about integration of  Facebook Connect’s functions or tools with your own web application. As a .NET developer, I did this integration with ASP.NET. So let’s start with a scenario.

As you have seen, Minepla.net use Facebook Connect and fb:comments to get comments from users. In simple way, comment mechanism is done by Facebook Platform. All comments are stored in Facebook’s data repositories as data of a Facebook  Application(like Minepla.net). So everything is fine so far, cause I do not need to care about comment mechanism for my web site. But maybe I can also want to store comments in my own database for some reason. So I need to get Facebook Connect’s fb:comments properties within my page. Storing in database is not so difficult after we can send data to the server. So let’s first look how we can take the data from Facebook Connect and send to the server. First of all create an *.aspx file and put fb:comments elements to your page.

<%@ Page Language=”C#” AutoEventWireup=”true” CodeBehind=”Default.aspx.cs” Inherits=”FacebookTutorial._Default” %>

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>

<html xmlns=”http://www.w3.org/1999/xhtml” xmlns:fb=”http://www.facebook.com/2008/fbml”>

<head runat=”server”>

<title>Untitled Page</title>

</head>

<body>

<form id=”form1″ runat=”server”>

<asp:ScriptManager ID=”ScriptManager1″ runat=”server” EnablePageMethods=”true”>

</asp:ScriptManager>

<div>

<script src=”http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php”

type=”text/javascript”></script>

<script type=”text/javascript”>

FB.init(“YOUR APP. KEY”, “xd_receiver.htm”);

</script>

<fb:comments id=”tut_comments”>

</fb:comments>

<div id=”info”>

</div>

</div>

</form>

</body>

</html>

With this page, you should be able to get comments from users. If users have Facebook account, they can login from their account and post a comment as a Facebook user to this page. So far there is no data stored in your application. Just a data is transferred to Facebook with help of this page. The comments are displayed in this page and also in Facebook.

facebook_aspnet

Fb:comments is one of the tags in XFBML(Facebook Markup Language). To use these tags you should add  xmls:fb=http://www.facebook.com/2008/fbml definition to your page. You can find other prerequisites at Facebook’s developer pages.

So now we have to take the text value from comment box and send it to the server. To do this, we are going to write some JavaScript. Here it is;

FB_RequireFeatures(["Comments"],function() {

FB.CommentClient.add_onComment(function(comment) {

PageMethods.GetComment(comment.post, OnSucceeded, OnFailed);

});

});

function OnSucceeded(result, userContext, methodName) {

document.getElementById(“info”).innerHTML = result;

}

function OnFailed(error, userContext, methodName) {

}

With FB.CommentClient.add_onComment() function we are adding a function when user click send comment button on comment box. What we are writing in this function is just about PageMethods in Asp.net Ajax. The important thing in here is the parameter which is comment.post. Comment.post is the value in comment box. For this example we have just simple method in code behind.

[WebMethod]

public static string GetComment(string comment)

{

return “This comment: ” + comment + ” is written @” + DateTime.Now;

}

After sending values to server, do what you want to do.It is all yours now. So this is all. The main concept is just like this.In future, I am going to tell you more about Facebook Connect’s javascript API with Asp.Net examples…

You may find the online example of this article in here.

  • Mar
  • 20
  • 2009

SQL Server versiyonlarını öğrenme

Tags: , | View: 1,111 | Comments:

SQL Server’ın versiyon bilgilerine ‘registry’ sayesinde kolayca ulaşabiliyoruz. SQL Server’ların çalışıyor olması ya da herhangi bir database’e bağlantı yapmadan küçük bir kaç kod ile kolayca göstermeye çalışacağım. Bunun için öncelikle registry’daki SQL Server için olan ağaç yapısını anlamak gerekli.

İlk kurulumda, SQL Server KEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSSQLServer\MSSQLServer\CurrentVersion key’i altına CurrentVersion isminde mevcut versiyonu yazıyor.

Aynı makinaya başka bir SQL Server kurmak istediğimizde Instance olarak kuracak ve bunuda HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server altına koyacaktır. Mesela SQL2000 isminde bir instance kuracak olursanız, bu register’da HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\SQL2000 şeklinde yer alacaktır.

Aynı şekilde versiyon bilgileri de HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\SQL2000\MSSQLServer\CurrentVersion altında yer alacaktır.

Artık tek yapmamız gereken registry’den bu bilgileri çekmek.Aşağıdaki kod örneği ile bunu kolayca yapabilirsiniz.Güle güle kullanın…

            RegistryKey rk = Registry.LocalMachine.OpenSubKey(@”SOFTWARE\Microsoft\Microsoft SQL Server”);
            String[] instances = (String[])rk.GetValue(“InstalledInstances”);
            if (instances.Length > 0)
            {
                foreach (String element in instances)
                {
                    if (element == “MSSQLSERVER”)
                    {
                        Console.WriteLine(System.Environment.MachineName);
                        rk = Registry.LocalMachine.OpenSubKey(@”SOFTWARE\Microsoft\MSSQLServer”);
                        RegistryKey s = rk.OpenSubKey(“MSSQLSERVER”);
                        Console.WriteLine(“Version:” + s.OpenSubKey(“CurrentVersion”).GetValue(“CurrentVersion”));
                        Console.WriteLine(“Service Pack:” + s.OpenSubKey(“CurrentVersion”).GetValue(“CSDVersion”));

                    }
                    else
                    {
                        Console.WriteLine(System.Environment.MachineName + @”\” + element);
                        rk = Registry.LocalMachine.OpenSubKey(@”SOFTWARE\Microsoft\Microsoft SQL Server”);
                        Console.WriteLine(“Version:” + rk.OpenSubKey(element).OpenSubKey(“MSSQLSERVER”).OpenSubKey(“CurrentVersion”).GetValue(“CurrentVersion”));
                        Console.WriteLine(“Service Pack:” + rk.OpenSubKey(element).OpenSubKey(“MSSQLSERVER”).OpenSubKey(“CurrentVersion”).GetValue(“CSDVersion”));
                    }
                   
                }
            }

  • Mar
  • 20
  • 2009

Internet Explorer 8 çıktı…

Tags: , | View: 220 | Comments:

Ve sonunda….

http://www.microsoft.com/windows/internet-explorer/default.aspx

Uzun süredir beta konsepti altında yayınlanan Internet Explorer 8 son halini aldı ve yayınlandı…

  • Mar
  • 19
  • 2009

Mix’09 ve Silverlight 3 Beta

Tags: , | View: 214 | Comments:

Şu sıralar devam etmekte olan Mix’09 etkinliğinin ilk günü tamamlandı. Ve ilk gelen haberler şahane… Silverlight 3 Beta ve ASP.NET MVC Framework‘ün çıkmış olması beni en heyecanlandıran haberlerden diyebilirim. Hemen indirip kurcalamak lazım.

Mix’09 etkinliğini takip etmek için: http://live.visitmix.com/

  • Mar
  • 17
  • 2009

Minepla.net artık Facebook’lu :)

Tags: | View: 254 | Comments:

Artık sitedeki yazılara yorumlarınızı Facebook hesabınız ile kolayca iletebileceksiniz. Nasıl mı? Çok basit…Facebook’a login olarak siteye girdiğinizde site sizi otomatikman tanıyacaktır ve yorum yazmanıza izin verecek. Tabi ki isterseniz logout olup, anonim olarakta yorum yapabilirsiniz.

Bu konu ile ilgili ilerleyen günlerde güzel şeyler paylaşıyor olacağım…

  • Mar
  • 09
  • 2009

Entity Framework sorunsalları “Exception: Unable to load the specified metadata”

Tags: , , | View: 438 | Comments:

Eğer yukarıdaki hatayı alıyorsanız, config dosyanızda ki bağlantı cümleciğini kontrol edin.

<add name=”Entities”
connectionString=”metadata=res://*/Model.csdl|res://*/Model.ssdl|res://*/Model.msl;
provider=System.Data.SqlClient;provider connection string=&quot;
Data Source=127.0.0.1;Initial Catalog=MinePlaNET;Integrated Security=True;MultipleActiveResultSets=True&quot;” providerName=”System.Data.EntityClient” />

Koyu renkle belirttiğim isimlerin data modeliniz ile aynı isimde olması gerekmekte. Eğer manuel olarak data modelinizin ismini değiştirdiyseniz bu sorun ile karşılaşırsınız. Peki bunlar ne? Bunlar aslında 3 tane dosya, *.csdl,*.ssdl,*.msl. Entity Framework’ün arka tarafta kullandığı dosyalar.Bunlar Entity Framework kullandığınız projenin DLL’inde resource olarak eklenmiş oluyor.Her hangi bir projede DLL’i eklediğinizde bu dosyalar ile bağlantı cümleciğini oluşturuyor…Dolayısıyla manuel değişikliklerde bunlara dikkat etmek gerekmekte.

  • Mar
  • 05
  • 2009

ASP.NET MVC RC2 çıktı…

Tags: , , | View: 190 | Comments:

Sona doğru yaklaşıyoruz sanırım. ASP.NET için geliştirilmekte olan MVC Framework’ünün RC2 versiyonu yayınlandı. Yeni versiyon setup ve deployment konularında yenilikler içeriyor. En önemli yenilik hosting şirketleri için özel kurulum modu diyebilirim. Daha fazla ayrıntıyı buradan öğrenebilirsiniz.

  • Mar
  • 05
  • 2009

Follow me on Twitter

Tags: | View: 157 | Comments:

http://twitter.com/ArdaCetinkaya