Anonymous User, Logged In User nasıl kullanılır?

by oozturk 20. January 2009 10:54

Merhaba,

Hazırladığımız web sitelerinde hem kayıtlı kullanıcıların hem de anonim kullanıcıların haklarını ayarlarız, bazı bilgilerini saklarız ve daha sonra gösteririz. Bütün bunları da kod içerisinde yaparız. Aşağıda aklıma gelen bazı merak edilen ayrıntıları vereceğim, bunlar dışında sorununuz olursa bana e-posta atarsanız size hemen cevap verir ve bu listeye sorunuzun cevabını eklerim.

 

- Kayıtlı kullanıcının ID'sini nasıl alırım?

Kayıtlı kullanıcının ID'si aşağıdaki kod ile alınabilir.

     (Guid)Membership.GetUser(HttpContext.Current.User.Identity.Name).ProviderUserKey;

-Aspnet_Profile tablosundaki UserId kolonu ile Aspnet_Users tablosundaki arasında fark var mıdır? Varsa fark nedir?

Aralarında fark vardır. Aspnet_Users tablosunda yalnızca kayıtlı kullanıcıların listesi ve özellikleri barındırılırken, aspnet_Profile tablosunda kayıtlı ve kayıtsız (web.config dosyasında izin verildiği taktirde kayıtsız kullanıcıların da bilgileri saklanır)  kullanıcıların bilgileri saklanır. Ayrıca aspnet_profile tablsounda aspnet_Users tablosunda bulunan özellikler saklanmaz, onun yerine bizim saklamak istediğimiz başka değerler saklanır. (Örn. Son bakılan ürün kodu, Telefon numarası, vb...) Aradaki bu farktan ötürü Profile tablosunda UserId kolonunda anonymous (kayıtsız) kullanıcılar için otomatik olarak bir UserId yaratılır ve bu UserId değeri kod esnasında AnonymousID (Request.AnonymousID) olarak anılır. Eğer aspnet_Profile tablosunda değer(ler) saklayıp sonra onlara ulaşabilmek isterseniz ya da aspnet_Profile tablosundaki UserId değerine bağlı başka tablolarınız varsa kullanmanız gereken ID; Kayıtsız kullanıcılar için AnonymousID, kayıtlı kullanıcılar için ise UserId oluyor (Bu UserId'nin nasıl alınacağını bu makale içindeki bir önceki soruda cevapladım).

-Kayıtsız bir kullanıcımın profile'ında bazı değerler saklıyorum, bu kullanıcı kayıt olduğunda bu sakladığım değerleri nasıl kayıtlı kullanıcının değerlerine taşırım?

Bunun için Global.asax dosyasında bir event'i handle etmek gerekiyor.

     void Profile_OnMigrateAnonymous(object sender, ProfileMigrateEventArgs e)

Bu event'i yukarıdaki fonksiyonu global.asax dosyasının içine yazdıktan sonra, içine istenilen komutlar yazılabilir. Ancak bu konuda dikkat edilmesi gereken bazı hususlar var. İlk olarak kayıt olan kullanıcının kayıt olmadan önceki profile tablosunda saklanan değerleri otomatik olarak silinmez bunu silmek gerekir. Aynı şekilde kullanıcının cookie'sinde saklanan anonymousId değeri de silinmelidir. Bu iki işilem için aşağıdaki kodu da OnMigrateAnonymous fonksiyonunun içine yazmalıyız.

        AnonymousIdentificationModule.ClearAnonymousIdentifier();
        ProfileManager.DeleteProfile(e.AnonymousID);

Yani özet olarak aşağıdaki kodu yazmalıyız Global.asax dosyasının içine;

    void Profile_OnMigrateAnonymous(object sender, ProfileMigrateEventArgs e)
    {
        //Burada bir profile yaratıp içine değerleri kopyalamalı

        ProfileCommon pfcT= Profile.GetProfile(e.AnonymousID);

        Profile.TelNo = pfcT.TelNo;

        Profile.Save();

        AnonymousIdentificationModule.ClearAnonymousIdentifier();
        ProfileManager.DeleteProfile(e.AnonymousID);       
    }

 

- Profile kullanımını nasıl aktif hale getirebilirim? Bazı değerlerin kayıtsız kullanıcılarda da geçerli olması için ne yapmalıyım?

Profıle kullanımını aktif hale getirmek için web uygulamasının kök (root) klasöründeki web.config dosyasına aşağıdakine benzer bir kod yazmak gerekiyor.

<system.web> altına şunları yazmalıyız.

        <anonymousIdentification enabled="true" cookieName="deneme.anonyous" cookiePath="/" cookieless="UseCookies" cookieRequireSSL="true" domain="deneme.com"/>
        <profile enabled="true" automaticSaveEnabled="false" defaultProvider="DenemeProfileProvider">
            <providers>
                <clear/>
                <add connectionStringName="BaseSQL" name="DenemeProfileProvider" type="System.Web.Profile.SqlProfileProvider"/>
            </providers>
            <properties>
                <clear/>
                <group name="Genel">
                    <add name="FirstName" type="System.String" allowAnonymous="true"/>
                    <add name="LastName" type="System.String" allowAnonymous="true"/>
                    <add name="DateOfBirth" type="System.DateTime"/>
                    <add name="Sex" type="System.Boolean"/>
                </group>
                <group name="Iletisim">
                    <add name="CepTel" type="System.String"/>
                    <add name="YerelTel" type="System.String"/>
                    <add name="EMail" type="System.String" allowAnonymous="true"/>
                </group>
            </properties>
        </profile>

 

Bu örnekteki bazı satırların içinde allowAnonymous="true"ibaresi var, bu ibare sayesinde kayıtsız kullanıcılarında bu özelliklere sahip olması sağlanmış oluyor.

Şimdilik aklıma gelenler bunlar. Aklıma geldikçe eklemeye devam edeceğim.

İyi çalışmalar dilerim.

Comments

7/30/2010 8:51:32 PM #

No need to be gloomy guys, there's still a lot of positives to take.

Cursos-de-ingles-en-el-extranjero United States

8/8/2010 2:25:07 PM #

Hi there, awesome site. I thought the topics you posted on were very interesting

Wilmer Harbach United States

8/11/2010 8:19:00 AM #

Hi. I just noticed that your site looks like it has a few code problems at the very top of your website's page. Is it an older version of blogengine.net?  I'm not sure if everybody is getting this same bugginess when browsing your site? I am using a totally different browser than most people, referred to as lynx, so that is what might be causing my problem? I just wanted to make sure you knew. Thanks for posting some great postings and I will try to return back with a completely different browser to check things out!

Hypercom T7Plus Manual United States

8/13/2010 11:02:55 AM #

Blog Engine FTW! Anonymous User, Logged In User nasil kullanilir? is cool.  I am really interested and was wondering if anyone else had any other related posts they could suggest. I like writing squidoo lenses myself and would like to gather as much data as I can. Please take a look one of my little projects if you like

Porter Cable Battery United States

8/21/2010 9:27:36 AM #

You may have not intended to do so, but I think you have managed to express the state of mind that a lot of people are in. The sense of wanting to help, but not knowing how or where, is something a lot of us are going through.

sex chat United States

8/22/2010 7:17:20 AM #

This blog keeps me coming back. I love your work.

air jordan 11 United States

8/24/2010 5:44:30 PM #

I tried to follow your RSS however the link seems to be broken.  I'm going to come back tomorrow.

North American United States

8/25/2010 5:24:04 AM #

Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts.

adipex United States

9/2/2010 5:41:55 PM #

Thank you for the sensible critique. Me & my neighbour were preparing to do plenty of research about that. We got a fine book on that matter from our nearby library and also most books exactly where not as influensive as your information. I am pretty glad to see such information which I was searching for a long time.That produced really glad Smile

cream overmantle mirror United States

9/3/2010 6:51:03 AM #

Oh was het een wedstrijd? Echt raar dat wij meteen daarnaast stonden op te treden, haha

Cam Girls United States

9/5/2010 9:13:49 PM #

Simply want to say your article is astounding. The clearness in your post is simply impressive and i can take for granted you are an expert on this subject. Well with your permission allow me to grab your rss feed to keep up to date with incoming post. Thanks a million and please keep up the sound work.

Jayne United States

9/6/2010 5:04:57 AM #

Hello, This blog post is very interesting and easy to read.  I am a enourmous follower of the topics talked about.  I also find joy reading the comments, but I notice that alot of people need to keep on topic to try and add more to the original blog post.  I would also ask all of you to add this url to your favourite website to help spread the word.  Warm Regards

spyware removal software United States

9/8/2010 6:16:22 PM #

Nice info, many thanks to the author. It truly is comprehensible to me now, the usefulness and value is overwhelming. Many thanks again and good luck!

webpage United States

Add comment




  Country flag

biuquote
  • Comment
  • Preview
Loading



Hakkımda...

Aklıma gelen sorunlara çözümler yazmaya çalışıyorum burada. Eğer çözümünü yazmamı istediğiniz sorunlar varsa,  bana e-posta atın :-)

 Iyi kodlamalar..

RecentComments

Comment RSS

Tag cloud