MVC'de belirli bir action için kullanıcı kısıtlaması nasıl yapılıyor?

April 29, 2009 at 2:45 PMoozturk

Oluştuduğumuz MVC web projelerinde actionlara herkesin erişmesini engellemek isteyebiliriz. Mesela firma kaydı yaratılacaksa yalnızca belirli bir role mensubu kullanıcılarının bunu yapabilmelerini isteyebiliriz. Bu durumlarda o action'ın başına aşağıdaki gibi bir kod yazılmalıdır.

[Authorize( Roles = "Admins" )]
        public ActionResult Create()
        {
           //...

            return View();
        }

Eğer birden çok role mensubu kullanıcıların erişebilmesini istiyorsak Authorize satırını o role için de tekrar etmeliyiz.

[Authorize( Roles = "Admins" )]
[Authorize( Roles = "Users" )]
        public ActionResult Create()
        {
          //...

            return View();
        }

Bu kadar basit. Aynı kısıtlamayı controller class için de kullanabiliriz.

İyi günler!

Posted in: MVC

Tags:

Comments (23) -

Hi  blog im from manchester im thinking of doing a manchester solicitors blog, thanks for your info i got some useful tips for my blog.

Reply

This is actually my very first time i visit here. I discovered so many interesting stuff in your blog particularly it's discussion. From the tons of comments on your posts, I suppose I am not the only one having all of the enjoyment here! keep up the great work.

Reply

biodegradable bags, pet waste bags, biodegradable dog poop bag, biobags, biodegradable trash bags, green bags, dog poop bags

Reply

Options trading & option trading strategies you can learn now. The online option trading site - News, tips and options basics guide to all your options day trading and option investing needs.

Reply

What I've Learned After Try Any Home Remedies For Acne? I want to share my Experience About Home Remedies For Acne That Really Work Well !

Reply

Vampire Fancy Dress costumes to buy online,vampire fangs,kids vampire costume,mens and womens vampire costumes,plus size outfits and everything else vampire costume related to buy online! Next day delivery and great prices!

Reply

Your Kitchen, the very heart of your home. The place where you nurture and nourish your family. So what other project could be as rewarding as remodeling your kitchen. Not to mention, Kitchen remodels are proven to be one of the best return on investments of all home improvement projects. Oddly enough, even with the growing popularity of DIY home renovations, the typical price of kitchen remodels has remained relatively constant or even dropped a bit because of a drastic change in the U.S. Cabinet Industry. With the introduction of the imported RTA Cabinets, the small domestic cabinet makers have literally been blown out of the cheap cabinet business. Gone are the days when a builder could push the cheapest, particle board cabinets. Today, the consumer has demanded the kitchen be upgraded with all wood cabinets (no particle board), with more built in functionality of roll out shelves, lazy-susans, trash can pullouts, etc. Homeowners are now able to select their kitchen cabinets from a wide variety of woods, stains and door profiles and still keep the budget below the old "cheap cabinet" prices. Which brings us to the RTA-CABINET-MALL, the webs largest selection of the new (high quality) Cheap Cabinets. We have carefully selected multiple vendors to give you the greatest choices of the top selling rta cabinet door styles.

Reply

A insightful blog post there mate . Thanks for the post .

Reply

This really answered my problem, thank you!

Reply

Have you considered adding some videos to your article? I think it might enhance my understanding.

Reply

This really solved my problem, thank you!

Reply

This blog site is pretty cool. How can I make one like this ?

Reply

Have you thought about adding some relevant links to your article? I think it will really enhance viewers' understanding.

Reply

This site has a lot of really helpful stuff on it. Thanks for sharing it with me.

Reply

This blog has got some very useful info on it! Cheers for helping me!

Reply

A insightful blog post right there mate . Thank you for posting .

Reply

When are you going to post again? You really entertain  a lot of people!

Reply

If you could email me with any hints & tips about how you made your site look this cool, I would appreciate it.

Reply

This blog site is really cool! How can I make one like this !?

Reply

This blog is very good. How did you make it !

Reply

This blog has got lots of very helpful stuff on it! Cheers for informing me!

Reply

Brilliant, thank you, I will bookmark you now!

Reply

I like this blog site layout ! How was it made. It is really cool!

Reply

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading