Friday, 15 July 2011

c# - ensure that logged user have access only to his data -



c# - ensure that logged user have access only to his data -

i already asked similar question i'm wondering if solution can simplified. may notice want ensure logged user have access data. i'm using custom membership provider in mvc3.

[authorize(users=httpcontext.user.identity.name)] public actionresult userarea() {}

thanks

make new attribute , override authorizecore method:

public class customauthorizeattribute : authorizeattribute { protected override bool authorizecore(httpcontext.user user) { // authenticated site if (!httpcontext.user.identity.isauthenticated) { homecoming false; } homecoming true; } }

then on controller do:

[customauthorize(httpcontext.user] public actionresult mycontrolleraction() { homecoming view(); }

http://code.commongroove.com/2012/04/20/asp-net-mvc-simple-custom-authorization-by-inheriting-from-the-authorizeattribute/

c# asp.net-mvc

No comments:

Post a Comment