How To Make Roles.ApplicationName Threadsafe

Mar 11, 2011

I am currently writing a user management application which administers users in a single aspnetdb instance. This single instance contains multiple "applications" which all have roles assigned against the individual applications.

As each user can be a member of multiple applications I use Roles.ApplicationName to cycle through each configured application and then determine which roles they are a member of. After checking each application I set the Roles.ApplicationName back to the original application which is the management application.

The problem I am having is when multiple users eachview an individual application and a request for Roles.GetAllRoles() is made. Most of the time the roles that come back are for the intended application but sometimes the wrong application's roles come back due to other requests cycling over the Roles.ApplicationName per application.

I've since read that Roles.ApplicationName is not threadsafe and therefore should not be used in a web application but I would prefer to have a solution to this rather than having to rewrite the role model in the application.

Also, The aspnetdb applications are created via this administration system and therefore I cannot create multiple RoleProviders, one per application.

View 1 Replies


Similar Messages:

Configuration :: How To Choose ApplicationName And How To Create New ApplicationName In C#

Mar 23, 2011

How to create ApplicationName and how to choose ApplicationName in C #?

Example:

I have several different applications into the same database. How to choose in combobox Application name" in nato dovolim prijavo. At present this can fix it in web.config, but I would like all done in c #.

View 7 Replies

How To Make All Of The Roles Defined In RoleGroup> Required? (i.e. User Must Meet All Roles)

Feb 24, 2011

Let's say I have a rolegroup as follows:

<asp:LoginView ID="lvDoSomeStuff" runat="server">
<RoleGroups>
<asp:RoleGroup Roles="RoleOne,RoleTwo">
<ContentTemplate>
...
</ContentTemplate>
</asp:RoleGroup>
</RoleGroups>
</asp:LoginView>

Is there a way I can make it so that a user must meet RoleOne and RoleTwo to satisfy the RoleGroup? By default, if a user is in either of the two roles, they will be granted access. I know I can do this via the code-behind, but I'd prefer to be able to wrap some content template with this markup instead of having to wrap it in a panel and hide the panel programmatically.

View 1 Replies

Make A Button Visible For Two Roles?

Jan 5, 2011

I am trying to make a button visible for users that are either in admin or manager role. I can't seem to figure it out,

Code:
teamLists.Visible = Page.User.IsInRole("Administrators", "Manager")

View 1 Replies

How Does The ApplicationName Attribute Actually Work

Dec 20, 2010

why did asp.net team choose / as the default value of Membership Role application name rather than the project name that makes sense?

In addition, the application might not be deployed as the root application. It means that / is no longer

Edit 1:

For example: I create a project A first and deploy it. Later I create another project B and deploy it. If both projects use the default, they still work but it will be difficult to know which users come from each project.

For me, it is better if the default is set to the project name.

Edit 2:

I am talking about the applicationName attribute generated by Visual Studio in Web.config.
Why don't use the project name instead of / by default ?

<membership>
<providers>
<clear />
<add name="AspNetSqlMembershipProvider"
type="System.Web.Security.SqlMembershipProvider"
connectionStringName="ApplicationServices"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="false"
requiresUniqueEmail="false"
maxInvalidPasswordAttempts="5"
minRequiredPasswordLength="6"
minRequiredNonalphanumericCharacters="0"
passwordAttemptWindow="10"
applicationName="/" />
</providers>
</membership>
<profile>
<providers>
<clear />
<add name="AspNetSqlProfileProvider"
type="System.Web.Profile.SqlProfileProvider"
connectionStringName="ApplicationServices"
applicationName="/" />
</providers>
</profile>
<roleManager enabled="false">
<providers>
<clear />
<add name="AspNetSqlRoleProvider"
type="System.Web.Security.SqlRoleProvider"
connectionStringName="ApplicationServices"
applicationName="/" />
<add name="AspNetWindowsTokenRoleProvider"
type="System.Web.Security.WindowsTokenRoleProvider"
applicationName="/" />
</providers>
</roleManager>

EDIT 3:

After creating two applications (i.e., one as the root and the other one as the child app) and both have the same applicationName set to /, both application use the same ApplicationID. It means the slash has nothing to do with site domain tree. My confusion has been answered. So... why did Visual Studio set it to / (that makes confusion for me) by default?

EDIT 4:

I have two applications. One as the root application and the other one as the sub application under the former. Both use applicationName = "/". I got the result as follow in database: So what is the meaning of /? If no meaning, why did VS choose this confusing name rather than the project name?

EDIT 5:

From this article, I will make the summary:

If we remove applicationName attribute from web.config for both applications, the ApplicationName generated in database for the root will be "/" and the ApplicationName generated in database for the sub app will be "/subappvirtualdir".If we leave the applicationName to its default value of "/" for both applications, both root app and sub app will get the same ApplicatonName of "/" generated in database. If we change the applicationName to "any name you want" for both applications, the ApplicationName generated in database will be set to "any name you want" for both applications.

View 2 Replies

Configuration :: How To Get ApplicationName In The Second Web.config

Mar 27, 2011

I want to separate the connection to the database in database.config So that I have web.config separate data with database.config.

View 1 Replies

Security :: How To Add ApplicationName To Existing Website

Mar 25, 2010

I have a (internet) web site with the below web.config (everything works fine). How would I alter this to include an applicationName attribute. I wish to eventually have multiple web sites using the same ASPNETDB database.

<?xml version="1.0"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<connectionStrings>
<clear/>
<add name="LocalSQLServer" connectionString="Server=myserver.com; Database=MyDB; Uid=MyUser; Pwd=MyPassword; Trusted_Connection=False;" providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.web>
<customErrors mode="Off" defaultRedirect="~/Error.aspx"/>
<roleManager enabled="true"/>
<authentication mode="Forms"/>
<compilation debug="false"/>
<pages theme="Standard"/>
</system.web>
</configuration>

View 6 Replies

C# - Create User In Another Membership.ApplicationName?

Dec 6, 2010

I have an administration website - the users of which should be able to modify users for a public site. This means the administration site has a valid membership provider, but I want to be able to access/change members in another site (and therefore ApplicationName).

First thought was to set ApplicationName on the Membership static - but that seems like a bad idea according to answers here: Changing Membership.ApplicationName in code - thread safety.

Second thought was to duplicate the MembershipProvider entry to the web.config - so now I can do WebSiteMembershipProvider = Membership.Providers("WebsiteSqlMembershipProvider") - but I can't now seem to get to a 'Membership' object which will let me (for example) call the standard 'CreateUser' method.

I tried WebSiteMembershipProvider.CreateUser - but it takes a load more parameters, and doesn't seem to do anything if I poke some values into it.

Am I nearly there? Or do I need a different approach? There's always the SqlProvider's stored procedures, I suppose...

View 2 Replies

Get Server Error In '/Applicationname Application ?

Jan 15, 2010

I have an asp.net page which I created using Visual Web Developer Express 2005, and locally everything works file as expected however when I uploaded the content of site into the online server one of the functionalities do not work and instead I get an error saying:

Server Error in '/Applicationname Application

Where the Applicationname above is replaced by them name of my application. It also state runtime error under the abve line.

And I am wondering if anyone could let me know what the problem is and how I could solve this issue.

For information I am using ASP.NET 2.0 and SQL Server 2005

View 3 Replies

Configuration :: Changed The ApplicationName In The Web.config Users Cannot Log In?

Sep 2, 2010

I changed the 'applicationName' attribute of all the providers in the web.config file from its default value of "/" to an actual name "/sampleName" and I have also changed it in the aspnet_applications table in the asp.net database.

Now users cant login... Why?

I am trying to do this to 2 web applications I have inorder for them to share 1 asp.net database

What I have done wrong or omited?

View 1 Replies

Sample C# Code To Manage Roles With Roles Provider?

Sep 21, 2010

i want to implement asp.net role provider to assign users over my LAN to roles and have my asp.net intranet app implement security based on roles.

i dont want to use VS to manage this with the built in tools but rather hand this off to users to manage themselves. i want an admin folder with a page(s) for admin roles to be able to create/edit roles and manage users in roles... this way an admin can add a domain user (MyDomainUsername) to a role such as ProojectManager or Tester or Developer... and users wont need to contact me for these tasks...

can anyone provide me a link (or some sample code) to some sample i can use to admin roles and users over a LAN in asp.net with c#?

View 1 Replies

Security :: How To Hide Multiple Roles With Roles.getallroles()

Mar 7, 2011

I have a multi level application that I am developing and need to block multiple rows from being joined. I know how to hide one role but I cannot figure out how to hide multiple.

Here is my current code

[Code]....

View 2 Replies

C# - Changing Membership.ApplicationName In Code - Thread Safety

Dec 5, 2010

On the MSDN page for the Membership.ApplicationName property (which applies to an asp.net membership provider), it warns that although one can change Membership.ApplicationName in code, 'The ApplicationName property is not thread safe for multiple writes, and changing the ApplicationName property value can result in unexpected behavior for multiple users of an application.' They therefore recommend avoiding using it for a 'web application'.

This is because the default SqlMembershipProvider is written as a singleton. But here's my question: is it OK if all the threads in my application process are going to set Membership.ApplicationName to the same thing?

I'm thinking of having multiple applications on my IIS box, each with their own separate application pool. I want to point them to the same location, but based on the hostname, set the application provider to different things. Wouldn't this actually be OK? It might not be a thread-safe operation, but doesn't each application pool have its own process and therefore its own instance of SqlMembershipProvider? So, every thread that tried to set Membership.ApplicationName for a given SqlMembershipProvider instance would be trying to set it to the same thing (the provider that is appropriate for that hostname).

View 1 Replies

Security :: Change The Membership Provide ApplicationName From Web.config?

Feb 9, 2010

I have a custom security module which is retrieving the applicationName of the defalut Membership Provider. I am using this value for convenience only. I mean, sometimes, I will authenticate the user as per "Windows Authentication" where there is no Login Form, and yet, I need to access the "applicationName" of the membership provider.So, in some of my applications, I am not using a memberhsip, and I leave it empty. And I found out that if the <membership> is not defined in web.config, it will default to "AspNetSqlMembershipProvider" type "System.web.Security.SqlMembershipProvider".I can add an key in <appSettings>, but I like to using the applicationName of the default membership provider, becuase in other applications I am using Forms Authentication, with a custom membership provider.If try to setup a dummy memberyship provider, I will get error that the connection string is empty.How I can set the "applicationName" property in web.config if I am using "Windows" authentication, and I have no membership provider ?

View 1 Replies

Configuration :: Change ApplicationName In C# Or Gobal.asax, Or Web2.config?

Mar 24, 2011

[Code]....

How to change ApplicationName in C# or gobal.asax, or web2.config

View 1 Replies

Security :: Automatically Assigning Roles / Standard Practice For Assigning Roles To Newly Signed-on members?

May 17, 2010

Newb question: what is the standard practice for assigning roles to newly signed-on members. Is it usually manual or is there a way of automatically assigning roles. Being completely new to this, I am confronted by the issue of my site having three different roles that new members could fall into, but am unsure about how to assign each a role. I can't imagine having to go through the process manually if I have thousands of members.

View 6 Replies

Get All Roles, But A Select Few / Get All The Roles Except Administrator?

Aug 13, 2010

I have run into a problem where I need to remove certain items from collections that seem to only have get all functions.

My Idea is to get the full collection and then remove the unneeded items. Then take that new collection and bind it to whatever I need.

For example How do I get all the roles except administrator?

Roles strRoles = Roles.GetAllRoles()
RoleList.DataSource = (Roles) roles; //Roles.GetAllRoles();
RoleList.DataBind();

or How do I get all users but say user123

MembershipUserCollection users = Membership.GetAllUsers();
UserList.DataSource = users;
UserList.DataBind();

View 1 Replies

AJAX :: Making Custom Accordion / Just Make A Button That Would Hide First Pane But Cant Get To Make It Work?

Sep 3, 2010

I would like to make a custom accordion, in which I have 2 panes, but where you couldn't open the second one until you clicked a validation button in the first one that would open the second...

I tried to just make a button that would hide the first pane but I cant get to make it work.

[Code]....

[Code]....

View 7 Replies

C# - How To Make The Content Of The Popup Make A PostBack Only When It's Appeared

Jan 29, 2011

I have a user control is shown through a SimpleModal popup (JQuery), this user control gets some data from database and displays them (the details of a record).

The problem is that this user control makes a round-trip to gets the data every PostBack for the parent page even it's hidden.

I wonder if I could make it gets its data only if the popup is appeared.

I tried to put it inside a Panel with false for Visible property and change it to true when I open the popup, but it stil call Page_Load which gets the data from database!

View 2 Replies

MVC :: Menu For Different Roles?

Feb 7, 2011

I am writing my first MVC 3 aplication (in ASP.NET) and I don't know how I can(should) display the menu for different users.

My app is created as MVC3 Web Application and the menu look like this:

[Code]....

Now, I want to show another links for user(Projects, Profile) and for admin(Manage Projects, Manage Accounts, Manage news). How I should do that?

View 5 Replies

How To Use Roles In A CMS System For C#

Jan 31, 2011

I am building a content management system and so far I am trying to get a member's area to work. I figured out the CreateUserWizard and the Login controls. I also used Roles.AddUserToRole(RegisterUser.UserName, "Member"); upon account creation to assign the user the role of a "Member". I have been googling but I havent been able to find a solid way on how to restrict either a directory or a page to make it so that only "Member" users can access it, otherwise redirect to login page. Can anyone give me an idea for this? Also I had a related question, when I go on to the site and I am NOT logged in, what is my default role? is it guest or just null?

View 2 Replies

How Does IPrincipal Get Its Roles

May 23, 2010

I need to get know how SiteMapProvider.IsAccessibleToUser() works. Built-in XmlSiteMapProvider calls HttpContext.User.IsInRole() which uses System.Security.Principal.GenericPrincipal in case of forms authentication.

Where does the current user gets its roles? Which provider loads this kind of information? I want to overload it and use custom logic.

View 2 Replies

MVC :: Specify Roles In Web.config

Nov 30, 2010

I want to be able to specify which roles having access to certain controllers in web.config and use it something like this:

[Code]....

..but the compiler says "Error 1 An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type...". How to accomplish this behavior?

View 3 Replies

Can User Have More Than One Roles

Apr 3, 2010

I'm developing a web application I want to use the role authentication to control different parts of the website accessibility. But my problem is say I implemented a upload and download functionality on one of the page and I want to have the ability to control a user whether they can either upload or download; or both. So, I'm not exactly sure if the role base authentication can support a user with more than one role to work the way I want it.

View 1 Replies

PDF With Search And Roles?

Sep 24, 2010

I have a pdf file that will be stored in a website and based from roles it will call the certain pdf files. (done with this save pdf inside a folder then call it using sitemap per pdf files according to roles) but I need a search page that will search a given pdf file name based on their roles, they can only see the pdf that is intended for them then via link it will then see all the pdf that was search.

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved