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


Similar Messages:

Thread-safety In .NET With AJAX?

Dec 17, 2010

The question is, is it possible that requests for the same session are executed from multiple threads? Are methods in ASP.NET reentrant? Especially we are using AJAX which means that asychronous requests are taking place.

Would this mean to place locks around operations on objects placed inside the session?I know that locks are essential when handling static and application wide variables, but the question is is the same true for session objects?

View 2 Replies

Thread Safety In Parameters Passed To A Static Method

Jan 10, 2011

Assuming a static method like below is called from ASP.NET page,can a different thread(b) overwrite the value of s1 after the first line is executed by thread(a)?If so, can assigning parameters to local variables before manipulation solve this?

public static string TestMethod(string s1, string s2, string s3)
{
s1 = s2 + s3;
....
...
return s1;
}

Is there are a simple way to recreate such thread safety related issues?

View 3 Replies

Thread Safety Around "web" CurrentSessionContext / ISessionFactory.GetCurrentSession?

Jan 31, 2011

I've seen some code that puts a lock around the following code:

if (!CurrentSessionContext.HasBind(sessionFactory))
{
CurrentSessionContext.Bind(sessionFactory.OpenSession());
}

ISession session = sessionFactory.GetCurrentSession();
[code]...

sessionFactory is a DI-injected singleton and the configuration uses a "web" (not "managed_web") context.

Am I correct in assuming that this code does not require synchronised access?

View 1 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

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 :: 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

C# - Dynamically Changing Master Pages / Getting Thread?

Sep 13, 2010

I created this master page file and in its Page_PreInit added the code to change master page at run time after detecing a visitor's country:-

Now, while researching I came across this thread that says "Setting the master page in Page_PreInit event is against the design and spirit of MVC..what is this supposed to mean ???

If not this way, how else am I supposed to change master pages at run time???

View 1 Replies

Cross-thread Operation Not Valid: Accessed From A Thread Other Than The Thread It Was Created On

Apr 2, 2010

I want to remove checked items from checklistbox (winform control) in class file method which i am calling asynchronously using deletegate. but it showing me this error message:-

Cross-thread operation not valid: Control 'checkedListBox1' accessed from a thread other than the thread it was created on.

i have tried invoke required but again got the same error. Sample code is below:

[code]....

View 1 Replies

Security :: Thread Safe Custom Membership Provider

Feb 2, 2010

I just created a custom membership provider I would like to know if I can make calls to my data access layer and not put my data access code inside the membership methods will that prevent my custom membership provider from being thread safe, for example:

public override [Code]....
CreateUser(string username, string password, string email, out MembershipCreateStatus status){ // DB calls to my data layer}v.s.public override [Code]....
CreateUser(string username, string password, string email, out MembershipCreateStatus status){ // data access }

View 2 Replies

Changing The Password Format In Membership?

Mar 1, 2011

How do I change the required password format in membership?

View 2 Replies

Manually Changing Username In Membership?

Jan 26, 2010

I am able to change a username by directly accessing the asp.net membership user tables. However, the old username is preserved in a new row and assigned a new UserID automatically by asp.net. How do I stop that from happening?

EDIT: only in the users table and roles table, not the membership table.

var mUser = dc.aspnet_Users
.Where(u => u.UserId == (Guid)user.ProviderUserKey)
.Select(u => u).SingleOrDefault();
mUser.UserName = newName;
mUser.LoweredUserName = newName.ToLower();
try
{
dc.SubmitChanges();
}
catch
{}

View 3 Replies

ConfigurationErrorsException "Thread Was Being Aborted" On Membership.Provider

Feb 7, 2010

System.Configuration.ConfigurationErrorsException - System.Web, Thread was being aborted.
(C:Inetpubweb.config line 417)
at System.Web.Security.Membership.Initialize()
at System.Web.Security.Membership.get_Provider()
[code]...

When it does the app needs to be restarted to clear the error, every page request after this raises the same bug. Line 417 is the Membrship provider add line in web.config. We're using the UpmMembershipProvider from MS Commerce Server, but it doesn't seem to be hitting this code, it's dying on the ConfigurationErrorsException inside System.Web.Security.Membership.Initializ

View 1 Replies

VS 2008 Changing Default Database In.NET Membership Provider?

Nov 17, 2010

When i add asp.net membership provider it uses some default database to add those records?How to change the default database to my own sql database?

View 1 Replies

Security :: Changing The Membership / Role Provider At Runtime?

Jul 24, 2010

I started out with the following code which worked fine, no problems:

[Code]....

I've since expanded the above so that it uses different providers according to the current logged in user. Here's the code since my changes:

[Code]....

I'm not getting any error messages but when I view the web page in the browser, it is stuck in a continuous loop where the page displays (correctly), then posts back to the server and displays again.

View 1 Replies

What Is The Result Of Setting The Current Thread's Culture Code

Jun 2, 2010

what is the result of setting the current thread's culture code?

I understand if I use the resource file it will pull label's/strings from the .resx file.

What else? Will it effect my date/money formatting also?

View 3 Replies

Visual Studio :: Debug A Multi Thread Program To See Local Variables Of Each Thread Using 2008

Jan 27, 2010

How can we debbug a multi-thread program to see local variables of each thread using visual studio 2008.

View 1 Replies

Architecture :: How Can Thread Update A Variable Shared With The Main Thread

Nov 24, 2010

I'm new to threading and have used it successfully, but limited. I can spawn a thread and have the main thread reference variables in the spawned thread, but I don't know how to allow the spawned thread to reference (and update) variables in the main thread.

Any example threading code I've seen on the web appears to be WAY more complicated than what I do, so I am unable to understand or integrate into my code.

Here is a quick example of how I use threading:

[code].....

View 3 Replies

Safety After Writing Some Data To HtmlControl?

Jul 15, 2010

I have a hidden input on my form, and my JavaScript code writes there dynamically generated string based on the user behavior on the page.Later, I access to that inpput via server side code.Many users will be using this page at the same time, so what about thread safety ?I mean, could it be possible that userA has an access to that string generated by userB ? Or maybe server will read that string from each user's Web Browser ?

View 2 Replies

What Are The Differences Between Currently Executing .NET Thread And Win32 Thread

Mar 24, 2010

I am reading the Asp.net security documentation on msdn.I come across these tow terms and get really confused.

# WindowsIdentity = WindowsIdentity.GetCurrent()

which returns the identity of the security context of the currently executing Win32 thread.

# Thread = Thread.CurrentPrincipal

which returns the principal of the currently executing .NET thread which rides on top of the Win32 thread.

View 1 Replies

C# - Lock Thread.sleep Not Working With .NET Thread?

Jun 25, 2010

I have a password page and when someone enters an incorrect password I want to simply foil a brute force attack by having

bool isGoodPassword = (password == expected_password);

lock (this)
{
if (!isGoodPassword)
Thread.Sleep(2000);
}
I would expect that this would allow all correct passwords without stalling, but if one user enters a bad password another successful password from a different user would also be blocked. However, the lock doesn't seem to lock across ASP.NET threads.

View 4 Replies

Web Forms :: Use Thread.sleep Method For A Particular Thread?

Aug 27, 2010

I want a example of multithreading .i want to use it in a web form not on console.i am using C#.net .and how to use thread.sleep method for a particular thread.

View 5 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

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







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