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

January 20, 2009 at 10:54 AMoozturk

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.

Posted in: ASP.NET

Tags: , , , , , , , , , , , ,

Comments (53) -

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

Reply

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

Reply

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!

Reply

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

Reply

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.

Reply

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

Reply

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

Reply

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

Reply

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

Reply

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

Reply

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.

Reply

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

Reply

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!

Reply

I admire the valuable information you offer in your articles. I will bookmark your blog and have my children check up here often. I am quite sure they will learn lots of new stuff here than anybody else!

Reply

can't say I agree with your article however you do make some good points.  I like your layout you use in your site.

Reply

mmmm, I think you may be right in what you have said in this post. Whoever there will be many people will not agree with you.

Reply

I think the information laid out in your post is really superb. I've been working on a preliminary research project on this topic and your post really enlightened me with a number of concerns that I had. I am brainstorming a research paper for college and I?m currently following 65 blogs for review.

Reply

There are certainly a whole bunch more details to take into account, but thanks for sharing this article.

Reply

My first comment. Found your blog a couple of times inadvertently. Yours is one of those blogs I could start reading and not know when to stop.

Reply

How long have you been blogging for? I've been blogging for quite a while but still haven't got the hang of it completely. Wouldn't mind getting a few tips here and there.

Reply

That is some inspirational stuff. Never knew that opinions could be this varied. Thanks for all the enthusiasm to offer such helpful information here.

Reply

Hey check out my blog too. I hope i have some interesting stuff too

Reply

Substantially, the post is really the freshest on this valuable topic. I fit in with your conclusions and will eagerly look forward to your next updates. Just saying thanks will not just be sufficient, for the great clarity in your writing. I will instantly grab your rss feed to stay privy of any updates. Genuine work and much success in your business enterprize!

Reply

Wow. You ARE the greatest.

Reply

edlycalsxbgseboutbfb, http://stearnsandfoster.org stearns and foster, EvZjuKs. vlamivjkttgzmahxtnne, http://spaceheaterbuy.com space heater, DpqhENY.

Reply

lxjgeqsewfopsmb, <a href="http://spaceheaterbuy.com">space heater</a>, BbKdOvhtpkySbhGJizKs.

Reply

feqruhlvbymfywl, <a href="http://spaceheaterbuy.com">space heater</a>, zMoKsKpkJOEBAbqmuXCs.

Reply

ihtlybzajzywnpn, <a href="http://spaceheaterbuy.com">space heater</a>, VeiBvKwRBrnxrZwnePPY.

Reply

lwmbatjimvrrfrg, <a href="http://spaceheaterbuy.com">space heater</a>, XdBqdYkmFHUzYzxDJUsa.

Reply

ianijfwoaprslxr, <a href="http://spaceheaterbuy.com">space heater</a>, FBBxIBdFEnEPIXjFBdQj.

Reply

This site is cool. i visit here evaryday.

Reply

vezpbwerzgfgpwiacbmw, http://donnakaranshoes.org donna karan shoes , VGTrtFVhrMCmYkiVzU. hnkhbydllonxdrjiqobx, http://stearnsandfoster.org stearns and foster , fGKTxiVCbUQPZIyuiL.

Reply

Great site design!!!! Whattemplate did you use?

Reply

this is in point of fact cool since this is in point of fact ture, this will lend a hand alot of people out, all the clue's and hint's are awesome…yet to have respect from a exboyfriend keep your distance away from him, so you can work on yourself, while he wonder's "where are you" and also it gain's his respect towards you aswell and being to "easy" isnt a win to win…its just a lose if you think you will get him back by being a door mat, he'll think he has all the power over you without thinking of your feelings, so think at all times wizely when it comes to getting a exboyfriend back. it must be for the right reason's and do show him that you are sociable, if he thinks you arent…gain some jelously abit..yet get back to normal with himSmile it always seems to work, and guys…..dont play with girls minds just to make them intrested in you more, they are in a position smell that something is up…possibly not as fast as guys can yet the can feel it….pretty much smart chicks can..sorry guys

Reply

When I originally commented I clicked the "Notify me when new comments are added" checkbox and now each time a comment is added I get four emails with the same comment. Is there any way you can turn this off?

Reply

Whenever I visit this blog, there is always something interesting to read. Good blog!

Reply

Thnx so much for this! I have not been this thrilled by a post for quite some time!  You have got it, whatever that means in blogging.  Anyway,  You're definitely someone that has something to say that people need to hear.  Keep up the outstanding work.  Keep on inspiring the people!

Reply

Which dating network has the most users?

Reply

auvjalflhlclpijavi, http://fendisunglasses.org, ClSLNwZiisElLERMVxSX. hcrvwuiqsagqtjwhhs, http://donaldjpliner.org, aJbYcCcCextuYgmsnlLN.

Reply

I am sure you have spent some time to give this amazing post to us. I do not know how to thank you.

Reply

mxnwmoocamkomejmby, http://thesak.org , oEvbeWNQzuywzngfkqtt. oiilzxupawtzkpzgxu, http://kathyvanzeeland.org , LkJQDxuTekvZOBSqDdzE.

Reply

udrnahvscuorsacbiq, http://kathyvanzeeland.org , WkWQOHjUibogEgCqqehg. meqodlfaqmkfcpppor, http://mattresstopperbuy.com , qzHjZCxRxUYgKbKOOuGI.

Reply

Great site design!!!! Whattemplate did you use?

Reply

Substantially, the article is really the greatest on this deserving topic. I fit in with your conclusions and will thirstily look forward to your upcoming updates. Just saying thanks will not just be sufficient, for the wonderful lucidity in your writing. I will directly grab your rss feed to stay abreast of any updates. Good work and much success in your business dealings!

Reply

How did you make this blog site look this awesome. Email me if you get the chance and share your wisdom. I'd appreciate it.

Reply

I'm getting a browser error, is anyone else?

Reply

There are no wise few. Every aristocracy that has ever existed has behaved, in all essential points, exactly like a small mob.   -   G. K. Chesterton

Reply

Awesome article, a great deal of beneficial material.

Reply

The Simpsons make background as longest running American sitcom, animated system and longest American primetime entertainment series.

Reply

Just what i needed cheers for the knowledge. A Beautiful piece of info.

Reply

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading