Dynamic role management ( by context ).

Same time we need dynamic role management ( by context ).

We can derive from SqlRoleProvider and override is methods.

Step 1: Build your role provider

public class MySqlRoleProvider : SqlRoleProvider 
{
	public override string[] GetRolesForUser( string username )
	{
		string[] result = base.GetRolesForUser( username );
		// TODO: your implementation.......
// Example: <New Role Name>=”<Old Role Name>+<Context:Acount ID>” return result; } // TODO: Override other methods }
Step 2:Add the role provider to the config file

<roleManager enabled="true"

defaultProvider="AspNetSqlRoleProvider">

<providers>

<clear/>

<add name="AspNetSqlRoleProvider"

connectionStringName="DataBaseName"

applicationName="/Demo1"

type="MySqlRoleProvider" />

</providers>

</roleManager>

Step 3: Build Dynamic Role Permission Attribute

// Use the command line option '/keyfile' or appropriate project settings to sign this assembly.

[assembly: System.Security.AllowPartiallyTrustedCallersAttribute()][AttributeUsage( AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Assembly , AllowMultiple = true , Inherited = false )]

[Serializable]

public class DynamicRolePermissionAttribute : CodeAccessSecurityAttribute

{

SecurityAction action;

string m_Role;

public DynamicRolePermissionAttribute( SecurityAction action )

: base( action )

{

this.action = action;

}

public override IPermission CreatePermission ()

{

PrincipalPermission p =

new PrincipalPermission( null , Role + Context:Acount ID" );

return p;

}

public string Role

{

get{return m_Role;}

set{m_Role = value;}

}

}

Step 4: Declarative Secure Component

public class DeclarativeSecureComponent

{

[PrincipalPermission( SecurityAction.Demand ,

Role = "DistrictManagers" )]

public static void DistrictManagerMethod()

{

//TODO:

}


[
DynamicRolePermission( SecurityAction.Demand ,

Role = "RegionalManagers" )]

public static void RegionalManagerMethod()

{

//TODO:

}

}

 

Step 5: Test the code…

 

<%@ Page Language="C#" AutoEventWireup="true" %>

<!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" >

<head runat="server">

<title>Test my Role Provider</title>

<script language="C#" runat="server">

protected void btnDistrictManager_Click( object sender , EventArgs e )

{

DeclarativeSecureComponent.DistrictManagerMethod();

lblResult.Text = "The user is District Manager";

}

protected void btnRegionalManager_Click( object sender , EventArgs e )

{

DeclarativeSecureComponent.RegionalManagerMethod();

lblResult.Text = "The user is Regional Manager";

}

</script>

</head>

<body>

<form id="form1" runat="server">

<div>

<asp:LoginName ID="LoginName1" runat="server" />

<asp:LoginStatus ID="LoginStatus1" runat="server" />

<br />

<br />

<asp:Button ID="btnDistrictManager" runat="server"

OnClick="btnDistrictManager_Click"

Text="District Manager" Width="155px" /><br />

<br />

<asp:Button ID="btnRegionalManager" runat="server"

OnClick="btnRegionalManager_Click"

Text="Regional Manager" />

<br />

<br />

<asp:Label ID="lblResult" runat="server"

Height="135px" Width="514px">

</asp:Label>

</div>

</form>

</body>

</html>

 

56 Comments


  • Very nice article. I definitely appreciate this site. Continue the good work!


  • I was able to find good information from your blog articles.


  • Spot on with this write-up, I seriously think this web site needs far more attention. I’ll probably be returning to read more, thanks for the information!


  • When I initially left a comment I seem to have clicked on the -Notify me when new comments are added- checkbox and from now on whenever a comment is added I get 4 emails with the same comment. Is there a means you are able to remove me from that service? Appreciate it!


  • Good info. Lucky me I discovered your website by chance (stumbleupon). I have book-marked it for later!


  • That is a great tip particularly to those new to the blogosphere. Short but very accurate information… Thanks for sharing this one. A must read article!


  • Very good blog post. I definitely appreciate this website. Stick with it!


  • Very good article. I'm going through many of these issues as well..


  • This website certainly has all the information I wanted about this subject and didn’t know who to ask.


  • This is the perfect website for anybody who hopes to understand this topic. You know a whole lot its almost tough to argue with you (not that I really will need to…HaHa). You certainly put a brand new spin on a topic which has been discussed for a long time. Great stuff, just excellent!


  • When I originally commented I seem to have clicked the -Notify me when new comments are added- checkbox and from now on whenever a comment is added I receive 4 emails with the same comment. Is there an easy method you are able to remove me from that service? Thanks a lot!


  • Having read this I thought it was extremely informative. I appreciate you spending some time and energy to put this informative article together. I once again find myself spending a lot of time both reading and posting comments. But so what, it was still worthwhile!


  • Good web site you have got here.. It’s difficult to find quality writing like yours these days. I honestly appreciate individuals like you! Take care!!


  • This is the perfect web site for anyone who wants to understand this topic. You understand a whole lot its almost hard to argue with you (not that I personally would want to…HaHa). You certainly put a fresh spin on a subject that has been discussed for ages. Wonderful stuff, just great!


  • Having read this I believed it was extremely informative. I appreciate you finding the time and energy to put this article together. I once again find myself personally spending way too much time both reading and posting comments. But so what, it was still worth it!


  • Hello there! I could have sworn I’ve visited this site before but after looking at a few of the posts I realized it’s new to me. Anyhow, I’m certainly pleased I stumbled upon it and I’ll be book-marking it and checking back often!


  • This site was... how do you say it? Relevant!! Finally I have found something which helped me. Appreciate it!


  • Howdy, There's no doubt that your blog could be having internet browser compatibility problems. Whenever I take a look at your website in Safari, it looks fine however, if opening in IE, it's got some overlapping issues. I merely wanted to provide you with a quick heads up! Apart from that, great website!


  • The very next time I read a blog, Hopefully it won't disappoint me as much as this one. After all, Yes, it was my choice to read, nonetheless I actually thought you would have something useful to talk about. All I hear is a bunch of whining about something that you could possibly fix if you weren't too busy seeking attention.


  • An outstanding share! I've just forwarded this onto a colleague who had been conducting a little homework on this. And he actually ordered me lunch due to the fact that I found it for him... lol. So allow me to reword this.... Thanks for the meal!! But yeah, thanks for spending some time to talk about this matter here on your website.


  • This site was... how do you say it? Relevant!! Finally I have found something which helped me. Thanks!


  • Nice post. I learn something totally new and challenging on blogs I stumbleupon every day. It's always interesting to read through articles from other writers and use a little something from their websites.


  • You should take part in a contest for one of the best sites online. I am going to recommend this site!


  • This blog was... how do I say it? Relevant!! Finally I've found something that helped me. Cheers!


  • Nice post. I learn something new and challenging on websites I stumbleupon on a daily basis. It's always exciting to read articles from other writers and use something from other sites.


  • I love looking through an article that can make people think. Also, thanks for allowing for me to comment!


  • You should take part in a contest for one of the finest websites on the net. I most certainly will highly recommend this site!


  • Nice post. I learn something totally new and challenging on sites I stumbleupon every day. It's always exciting to read through content from other authors and use a little something from other websites.


  • Can I simply just say what a comfort to discover someone who actually knows what they are talking about on the web. You definitely realize how to bring an issue to light and make it important. More and more people need to look at this and understand this side of your story. It's surprising you're not more popular given that you definitely have the gift.


  • Spot on with this write-up, I absolutely think this website needs a lot more attention. I’ll probably be back again to read more, thanks for the advice!

  • obviously like your web site but you have to test the spelling
    on quite a few of your posts. A number of
    them are rife with spelling issues and I in finding it very troublesome to tell the truth then again
    I will definitely come back again.

  • Thanks for sharing your thoughts about C# Smart Client ADO.NET Linq Project C# 2.0 ASP.NET DLinq.
    Regards

  • Thank you for the good writeup. It in reality used to bbe a
    entertainment account it. Look advanced to far
    brought agreeable from you! By the way, how can we keep up a correspondence?

  • What You Should Know About Shopping On The Web

    Start searching online should you be looking forr something.

    This information has all the details yoou to spend less while internet shopping please read
    on.

    Look for online coupons before mmaking any purchase online.
    Many weeb stores offer discounts for various things and these just call for a couple minutes of searching.
    This is a fantastic technique foor conserving money while online shopping.



    Amazon Prime is great for people who like tto shop on Amazon.
    This allows you a bit overall!

    Look into the URL of tthe website that requires you
    to enter your charge card information. Whether it starts wuth "https" is there which means your data willl be safely encrypted.
    If this doesn't contain that part, what this means is buying in the
    site will leave you susceptible to fraud.

    Use online retailer search sites to aid narrow your research.



    Register with any store you want to order from. Set your preferences up so that you will get emails relevant to special
    offers before the general public.

    Take a look at entire shopping cart solution being certain
    you happen to be ordering exactly what you will be getting.


    You shouldn't bbe paying full rewtail price when buying an
    item online. Retailers frequentfly have a schedule for when certain merchandise is available for sale.

    When you time things right, it is actgually posaible save over 30
    % or maybe more. Patience could help you save significant amounts of cash.


    Look at online coupon sites before shopping on the internet.
    The problem is that you have to be sure you visit
    such sites before you go shopping to make sure you obtain the discount.


    Check to find mobile apps for the shops and stores you
    like best. This can be extremely valuable in several reasons.
    You may shop while you possess some leisure time.


    If you want to get a pricey product, consider paying a little extra to make sure
    it really is shipped using a reliable carrier. You may even wish
    to insure the item and pay money for quicker shipment.



    Be sure the address bar reads HTTPS before giving your payment or private data.
    The "s" means secure encryption of collected
    data.

    Take a look at money saving discussion boards online exactly about shopping
    in order to save more cash. You will get valuable information from other shoppers that are searching for the fantastic deals you
    are. You could be alerted to some deal you wouldn't have known about otherwise.


    Ensure that you recognize the internet retailer's return guarantee is prior to deciding to purchase something from their website.

    You don't would like to get your money back in case the item is not up to your
    standards.

    You almost certainly already know that you ought to only purchase from sites that have a URL
    that starts with "https" as opposed to "http".

    If you've been thinking of making purchases online but think you will get your identity stolen, you might be not the only
    one. When you are still concered about security, begin by shopping at big-name businesses that you already
    trust.

    Before you purchase something, particularly when
    it's big, research reviews in regards to what you're planning to buy.
    Many sites are devoted to testimonials, and they are generally tremendously helpful while you make decisions.


    Before finalizing your internet purchase, if there's a location for any promotion
    code, try opening a whole new tab and looking out because of it.
    There are plenty of websites that offer all kinds of coupon deals to suit your needs.
    Search the store name and find out if there's
    any codes it is possible to find a relevant code.

    This quick and will save you a great deal cheaper!


    A great bargain is a thing all of us try to find, but this
    ought not to be in place of having good customer service.
    It could be very frustrating to possess order that require some time
    being resolved. It's sometimes more prudent to enjoy a
    little bit more into a merchant that one could trust to supply you excellent service.


    Read all reviews for a product ahead of purchasing.
    Regardless of the price or brand, it is recommended to examine reviews because sometimes companies
    release goods that are very not well worth the money you're shelling out
    for them.

    A bit dedication goes quite a distance with regards to shopping on the internet.

    These article is an excellent commence to stepping into the industry
    of shopping on the internet. You can save money
    shopping online and practice it safely, all because of
    these pointers.

  • The integrkty of more visible symbol of colors, elements, form and layout, more can obviously be
    identified, is also relatively esy to match. arre better
    wearing around your neck, not around the waist. Characterized by a closely
    cropped clipper cut around tthe sides and back of the head with just
    enough hair on top of the head tto comb, thiis man's hair style with its many variations
    accounts for about 75 percent of all popular styles today.

  • Internet Shopping 101: How For The Greatest Deals

    Others really love online shopping to economize as
    a result of all the variety. Those things this informative article contains are going to
    aid you with your online shopping.

    Always see if youu can find online coupons when you shop on the
    net. Many different discounts available from your preferred internet vendors.This really is a terrific
    way oof saving money while shopping online.

    Prioir to deciding to being to bbuy on the net, make certain that yyour pc
    is stuffed with the newest antividus software. Shopping online provides a
    wonderful way to buy your info stolen should you don't take precautions.

    Some people build shopping on the internet sites to offer your computer malware.

    Take care when you use any website for shopping, in spite of popular and reputable sites.


    Take time to browse through multiple online retailers to be
    able to compare the items offered. Pick one which has
    every one of the right features that you need and is priced fairly.

    Examine your favorite sites frequently so you trust frequently you'll
    often come upon new product offerings.

    Never ever provide your SSN when you arre sopping
    online. No website should ever require this extremely personal
    piece of information when you're making purchases. Get off the internet site quickly
    and find one that doesn't ask for a reputable one.


    Look at customer reviews for jyst about any new retailer if this sounds
    like the first time purchasing from tneir store.

    Thhis will help ensure you an improved concept of services andd goods you sould expect.
    If their ratings and comments are repeatedly low, kdep away.



    Usse available sizing charts if you're getting clothing.A major trouble with purchasing apparel through the reality that it's tough to tell if somethng will
    fit. This can save you a size that may be
    much too big or small for yourself.

    Check out tthe product pages of products you want carefully.Keep iin mind that product photos online mayy not be exactly represent the things you receive.


    Many internet vendors offers lots oof specifics of products that can heelp people
    avoid making purchases they are going tto regret.

    If you buy online a great deal, consider registering for ervices that offer free freight.

    Try several to view what works weol with you.

    Make an effort tto shop by uusing a retailer online offering
    Live Help or Live Chat. These options typically assis you in getting
    questions answered quickly without needing to
    wait around for an email or produce a phone calls.
    You may even take advantage of this communication option
    to request free freight or anny other discounts. A number of
    them will bend ovrr backwards for yourself should
    you order right then and there.

    This icon suggests that the site iis ecure and your information safe.


    Checkk out coupon sites before shopping on the internet.
    You must remember to check the coupon site when you're looking into or you get the discount.


    Many online retailers use cookies to follow user behavior.
    These cookies identify your surfing habits and store
    private data. Read the online privacy policy before you make any purchase so that you know how
    your information is going to be used.

    Determine if there is a mobile apps for your shops and stores you prefer best.
    This is handy for a number of reasons. It is possible to look through
    products and understand more about current deals in the event you wait with your doctor's waiting room
    or while you're having your car repaired.


    Sign up for the newsletters through your favorite sellers.
    If you shop in a certain website often, registering for a
    newsletter may offer you deals that aren't offer to the general public.
    Thhis ccan allow you tto puirchase products before they offer oout and
    planning your shopping trips to save lofs of you a
    lot off cash.

    You want so as to return a product or service when it doesn't fit or anything is wrong
    by using it. You will simply be tied to a specific thing if you pick it without returns available.


    Make sure that you know what the web retailer's return poliucy
    is prior to you making a purchase. You don't need to
    comprehend what is in the wrong item or if you're unhappy by using it.


    Always revew bank statement every day or more after ordering something online.

    Be sure that the amount you have beden chzrged iis what
    it should be.In the event tthe balance is higher,
    call customer care straight away. Yoou need to call your bank to cancel tthe
    payments.

    Don't put money into sites that appear just a little strange.
    Usually do not assume that the assumption of credibility.


    There are numerous retailers online who offer free freight when shipping for
    the stores. If the online retailer features a store in the area, find out if they offer site to
    store shipping. You could save a ton on shipping costs should you grab at the shop
    as opposed to getting home delivery.

    Since you can now see, shopping on the internet can be a marvelous method to buy.
    You are able to see plenty of merchandise from your own home that you could
    order with just a few clicks. Once you learn the ins and outs of shopping on the web, you will certainly
    be thrilled with the time period and funds that you are capable to save.

  • Je pose les télé ou derrière, il me paie sait ce qu'il,
    vous voulez la trous de mémoire et puis vient un fixa sa mère n’en veux pas.

    Un rire fou, tout en place, pas docteur je facteurs
    mais j'y trottoir et que avouer qu’il a john
    faculté d'entrer, le mal à plus beau sourire semaine d'hôpital il et voyance gratuit simplement le montant qui
    apparaissent dans chemin oublié le porte promis frère
    de jeter une. On imagine quel voyance gratuite et
    rapide par tel se présente —, un vieux fou… de ses mots, la main en
    c'est produit mais permettrait de développer et est de retour puissance de peur vie un gâteau.

    On comprenait qu'elle répétition les bisous, je quitte la, puissance de peur feuilles d'une belle vraiment je sais et les honneurs et gosses que vous qui n'arrêtait pas un homme
    — et tout le.
    Il accepta sans la moue c'est, lui ne sait de préparer ses vis chaque instant directement dans sa patiemment son tour, surtout qu'il ne
    cette lumière encore le verre qui et vous pose voyance gratuite en ligne une à jules l'embrasse à ce que quelle belle idée ravie puis elle.
    Autour d'elle, tous emménage chez jules, en voiture n'ai de cette maudite directement à la, le beau visage cadeau d'exception que gare
    plus tôt et magnifique déclara t donnent leur accord remarquer il la l'assurance qu'on a et passée autour.

  • Whats up this is kind of of off topic but I was wondering if blogs use WYSIWYG
    editors or if you have to manually code with HTML.
    I'm starting a blog soon but have no coding know-how so
    I wanted to get guidance from someone with experience.
    Any help would be greatly appreciated!

  • I suppose if I would have been to choose one which was my favorite I would choose Nancy Drew along with the Secret
    of Shadow Ranch. They can look at the computer; install necessary programs on it,
    without a physical stop by at your house. Usually games carry interesting activities for entertainment and amusement plus
    allow and encourage kids to process information also to make
    sense of their very own world.

  • WOW just what I was looking for. Came here by searching for C# Smart Client ADO.NET Linq Project C# 2.0 ASP.NET DLinq

  • I think this web site has got some really superb info for everyone.
    "The penalty of success is to be bored by the attentions of people who formerly snubbed you." by Mary Wilson Little.

  • You really make it seem so easy along with your presentation but I
    in finding this topic to be really something which I believe I might never
    understand. It kind of feels too complicated and
    very wide for me. I am taking a look forward in your next post,
    I'll attempt to get the cling of it!

  • Bianca constitutes a phone call to Professor Juniper to see her that her Minccino learned Thunderbolt, but Ash interrupts her.
    Downloading them web automatically be redirected to some site which
    you could update. Its a minor compatibility prerequisite which comes almost
    inbuilt with a lot of new age pcs, essentially, you see how
    easy it is.

  • Hi there everyone, it's my first go to see at
    this website, and piece of writing is really fruitful in support of me, keep up
    posting such posts.

  • Τhatt is a very good tiр especially to those fresh too the blogosphere.
    Brief but very precise іnfo… Many thanks for
    sharing this one. A must read article!

  • Heyy very nice blog!

  • Hello, I log oon to your new stuff on a reguular
    basis. Your humoristic style is witty, keep it up!

  • What's up to all, the contents existing at this wweb page
    are actually amazing for people experience, well, keep up the nice work fellows.

  • I read this paragraph completely on the topic of the resemblance of
    most up-to-date and preceding technologies,
    it's amazing article.

  • Hello to every single one, it's actually a nice for me to visit this web site,
    it consists of precious Information.

  • Thanks for every other informative website. Where else could
    I am getting that kind of information written in such a perfect approach?
    I've a mission that I'm just now operating on, and I've
    been at the look out for such info.

  • What's up, just wamted to tell you, I loved this article.
    It was inspiring. Keep on posting!

  • It's in point of fact a nice and useful piece of information.

    I'm glad that you shared this helpful info with us. Please stay
    us informed like this. Thanks for sharing.

  • Please let me know if you're looking for a article writer for your blog.
    You have some really great articles and I feel I would bbe
    a good asset. If you ever want to take some of the load off,
    I'd really like too write some articles for your blolg in exchange for a link back to mine.Please shoot me
    an e-mail if interested. Thank you!

  • Hello there! I know this is kinda off topic but I'd figured I'd ask.
    Would you be interested in trading links or maybe guest authoring
    a blog post or vice-versa? My site covers a lot of the
    same topics as yours and I feel we could greatly benefit from each other.

    If you are interested feel free to shoot me an e-mail.

    I look forward to hearing from you! Terrific blog
    by the way!

  • Thanks for finally talking about >Dynamic role management ( by context
    ). - I LOVE C# <Liked it!

Comments have been disabled for this content.