473,795 Members | 2,830 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Implement authorization in win forms

Whats the best way of implementing authorization in a win forms
application.
I mean things like show/hide or enable/disable Save button ,creating
context menus etc.
Apr 10 '08
13 7479
Curoious - even though it accepts multiple ProvideProperty Attribute
declarations, only the first is used... never mind; change the
[ProvideProperty] line to:

[ProvideProperty ("Role", typeof(Componen t))]

Marc
Jun 27 '08 #11
On Apr 10, 10:49*pm, parez <psaw...@gmail. comwrote:
Whats the best way of implementingaut horizationin a win forms
application.
I mean things like *show/hide or enable/disable Save button ,creating
context menus *etc.
Hi,

Visual Guard .Net is probably a good solution:

http://www.visual-guard.com/EN/.net-...ion-tool#admin
Jun 27 '08 #12
On Apr 14, 4:01 pm, Marc Gravell <marc.grav...@g mail.comwrote:
I just one more issue... If a control has sub-control(compone nt) then
it does not show up for the sub components.
e.g MenuStrip control has ToolStripMenuIt em children. How do I make
it show up(in properties) for those controls.

I suspect that is because ToolStripMenuIt em isn't a Control, and I
restricted it to Controls; Changed as below (I also removed the events
stuff - didn't seem necessary in hindsight):

[ProvideProperty ("Role", typeof(Control) )]
[ToolboxItemFilt er("System.Wind ows.Forms")]
[Description("Pr ovides automatic role-checking")]
public class RoleDisabler : Component, IExtenderProvid er
{
private Dictionary<obje ct, stringmap
= new Dictionary<obje ct, string>();
[DefaultValue("" )]
public string GetRole(object obj)
{
if (obj == null) return "";
string role;
map.TryGetValue (obj, out role);
return role ?? "";
}
public void SetRole(object obj, string role)
{
if (obj == null) return;
if (string.IsNullO rEmpty(role))
{
map.Remove(obj) ;
}
else
{
map[obj] = role;
}
if (!DesignMode)
{
SetEnabled(obj) ;
}
}
private void SetEnabled(obje ct obj)
{
if (DesignMode || obj == null) return;
string role;
if (map.TryGetValu e(obj, out role))
{
IPrincipal principal = Thread.CurrentP rincipal;
bool isInRole = principal == null ? false :
principal.IsInR ole(role);
if (obj is Control)
{
((Control)obj). Enabled = isInRole;
}
else if (obj is ToolStripItem)
{
((ToolStripItem )obj).Enabled = isInRole;
}
}
}
bool IExtenderProvid er.CanExtend(ob ject obj)
{
return obj is Control || obj is ToolStripItem;
}

}
Hi Marc,

I added the following to the RoleDisabler .. and now it also enables /
disables everytime my permission changes..
Thanks again..

private void HookUpEventhand lers()
{

UserAccessInfo. UserPermissions Updated += new
EventHandler<Ev entArgs>(UserAc cessInfo_UserPe rmissionsUpdate d);
}

void UserAccessInfo_ UserPermissions Updated(object sender,
EventArgs e)
{
foreach (object obj in map.Keys)
{
try
{
SetEnabled(obj) ;
}
catch(Exception ex)
{

Trace.WriteLine If(Logger.Insta nce.TraceSwitch .TraceError,
ExceptionUtilit y.GetInnerMostE xception(ex).Me ssage);
}
}
}
Jun 27 '08 #13
Hi Marc

Firstly thanks for posting your code - it's proving very useful for me (and many others I'm sure).

I've tested the code on my forms and it seems to deal very well with most things but "falls down" a little with things like datagridviews etc where more than one property would be bound - the code you've posted can happily enable/disable the entire control (i.e. all cols) but how would you go about hiding/making readonly some columns dependent on roles (i.e. "CanView"/"CanEdit" type properties?

Thanks in advance
Martin
Jul 16 '08 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
4717
by: Ronald S. Cook | last post by:
In my ASP.NET app, I have a few pages that I want to be public (i.e. accessible by everyone) and the rest private (user has to be signed in). In the examples I've seen, the public files have been in the root folder with it's own Web.config file and the private ones in a subfolder with a separate Web.config file. Must I necessarily use a subfolder to separate private from public files? Could I maybe have them all in the same root folder...
4
1570
by: Mark Olbert | last post by:
I am having a devil of a time trying to get Forms authentication to work in a very simple test webapp (I've gotten it to work many, many times when developing on my WinXP client box, but I've just switched to doing development/debug on a Win2K server with IIS5, and something is obviously wrong). Here's the site: login.aspx /ssl/members/members.aspx
3
2516
by: nick | last post by:
Hi, How should I write the web.config file to allow some of the aspx files be executable to all users and others are required users to login? All the aspx files are in the same folder.
4
1984
by: Johnnie Norsworthy | last post by:
ASP.NET 2.0 How do I configure my web site to require forms authorization only for a subfolder off the root? I know how to set Web.config for forms authentication for the whole site, but I need the root folder to allow all read access, and a single subfolder to require authorization. Thanks for any assistance. -Johnnie
2
3074
by: Water Cooler v2 | last post by:
Is the authorization tag/class in web.config\<system.web> available only for Windows authorization? Does it make sense for Forms based authentication?
1
1834
by: sonu | last post by:
Mark is creating a website using ASP.NET. He is using Forms authentication for authenticating and authorizing users. He has the following layout of files and directories in his website: Root ....File Manager/ ....Files Employee/
1
1747
by: Anthony Small | last post by:
Hello, I have a login.aspx page that is associated with a theme. When I view the page login.aspx with forms authentication/authorization set as below in the web.config file the theme displays on the page as expected. <authentication mode="Forms"> <forms loginUrl="~/Pages/Login.aspx" protection="All" timeout="40" /> </authentication> <authorization> <allow users="*"/>
0
1259
by: yofnik | last post by:
Hello, Using policy (modifying web.config) and FormsAuthentication, is it possible to return an error message (or redirect to error page) instead of redirecting to the login page for specific users only? Here's an example: I have a section of my web app that is for admins only. The authorization section of my web.config looks like.
4
2423
by: xke | last post by:
Using web.config authorization settings, is it possible to allow my users to access default.aspx but not default.aspx?action=edit ?? <location path="default.aspx"> <system.web> <authorization> <allow users ="*" /> </authorization> </system.web> </location>
0
10443
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10216
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10165
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10002
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9044
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7543
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6783
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5565
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2921
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.