.net - How To Control MembershipProvider Instance Creation / Lifetime
Nov 16, 2010
I have registered a custom MembershipProvider class in my Web.Config file. I'm using Inversion Of Control using Castle Windsor and I have registered my custom MembershipProvider class as transient (because it's using a service that's transient as well).
This means that I want the Membership provider instance recreated on every web request. Currently, it is created only once per application domain so when it tries to access the service it depends on, that service instance is reused while it is not supposed to.
Now I need to find a way of having Windsor control the lifetime of my custom MembershipProvider but I don't know how. I expected a factory sitting around somewhere in the .NET Framework, allowing me to override the instance creation and rerouting it to Windsor but I can't find anything alike.
By the way, I'm using .NET 4.0.
UPDATE: Here's some of my code so you can see what I'm doing exactly:
[Code]....
View 2 Replies
Similar Messages:
Mar 29, 2010
My understanding of Factory Method Pattern is (Correct me if i am wrong) Factory Method Pattern "Factory Method allow the client to delegates the product creation (Instance Creation) to the subclass". There are two situation in which we can go for creating Factory Method pattern.
(i) When the client is restricted to the product (Instance) creation.
(ii) There are multiple products available.But a decision to be made which product instance need to be returned. If you want to create Abstract Method pattern
You need to have abstract product Concrete Product Factory Method to return the appropriate product.
public enum ORMChoice
{
L2SQL,
EFM,
LS,
Sonic
}
//Abstract Product
public interface IProduct
{
void ProductTaken();
}
//Concrete Product
public class LinqtoSql : IProduct
{
public void ProductTaken()
{
Console.WriteLine("OR Mapping Taken:LinqtoSql");
}
}
//concrete product
public class Subsonic : IProduct
{
public void ProductTaken()
{
Console.WriteLine("OR Mapping Taken:Subsonic");
}
}
//concrete product
public class EntityFramework : IProduct
{
public void ProductTaken()
{
Console.WriteLine("OR Mapping Taken:EntityFramework");
}
}
//concrete product
public class LightSpeed : IProduct
{
public void ProductTaken()
{
Console.WriteLine("OR Mapping Taken :LightSpeed");
}
}
public class Creator
{
//Factory Method
public IProduct ReturnORTool(ORMChoice choice)
{
switch (choice)
{
case ORMChoice.EFM:return new EntityFramework();
break;
case ORMChoice.L2SQL:return new LinqtoSql();
break;
case ORMChoice.LS:return new LightSpeed();
break;
case ORMChoice.Sonic:return new Subsonic();
break;
default: return null;
}
}
}
**Client**
Button_Click()
{
Creator c = new Creator();
IProduct p = c.ReturnORTool(ORMChoice.L2SQL);
p.ProductTaken();
}
Is my understanding of Factory Method is correct?
View 3 Replies
Jan 24, 2010
I'm trying to create a database within the app_data folder of an asp.net mvc project using the IDE, but i am getting a "Required Components Missing" message indicating "Connections to SQL Server files (*.mdf) requireSQL Express 2005 ....."
I am using
- Windows 7 Enterprise
- VS2008 Team System SP1
- SQL Server 2008 Developer Edition SP1
I have altered the database connection to use the default instance by setting to blank using
Tools -> Options -> Database Tools -> Data Connection : SQL Server Instance Name
I also note from the SQL Server Books Online that the user instance feature will be removed in the future, but for now it suits my effort in developing an application where a number of people are working on the project.
Has anyone managed to create a database in the same manner?
View 1 Replies
Apr 19, 2010
i developed a custom control (inherited from System.Web.UI.UserControl) which is used within a Gridview's TemplateField:
<sc:MyControl
runat="server"
id="my_ctrl"
AllowEditing="true"
NumberOfControls='<%# Eval("Count")%>' />
"Count" is an integer value from the GridView Datasource.
Based on this value i have to create some LinkButtons dynamically in my custom control (in Page_Init), which works very well when the value for NumberOfControls is hard-coded.
My problem is that the value of "Count" is not available (NumberOfControls = null) during Page_Init and therefore i can't decide how many controls there should be generated.
Is there any way to pass databinded values to custom controls so that they can be used earlier (as if the values were hard-coded)?
View 2 Replies
Sep 15, 2010
I say until you log out, session times out or you close the browser. But am I right?
I had an interview today and the interviewer wanted to know if I log into a page and closes the browser (without logging off), what happens to the session.
I said that the session will be orphaned. He says no - because their users are able to connect back to the session by just opening up the browser (using a cookie only). I told him that's a persistent cookie - not a session cookie. And I said that if that's the cause, there is nothing preventing the user from exporting the [persistent] cookie to a another computer and starting the session on that computer.
At first he said you can;t export a cookie but when I explained how, he said that he'll look but since many many people including 2 architects came up with the design, it is unlikely they are all wrong.
View 2 Replies
Jan 7, 2010
I am creating a class library , and i need to use Singelton pattern. Just wondering if the Grabage collectorwill ever clear the object created in Singelton class. How garbage collector deals with singelton?
View 3 Replies
Apr 4, 2010
There have been many question on managing EntityContext lifetime, e.g. http://stackoverflow.com/questions/813457/instantiating-a-context-in-linq-to-entitiesI've come to the conclusion that the entity context should be considered a unit-of-work and therefore not reused. But while doing some research for speeding up my database access, I ran into this blog post...Improving Entity Framework PerformanceThe post argues that EFs poor performance compared to other frameworks is often due to the EntityConnection object being created each time a new EntityContext object is needed.
To test this I manually created a static EntityConnection in Global.asax.cs Application_Start().
I then converted all my context using statements to
using( MyObjContext currContext = new MyObjeContext(globalStaticEFConnection)
{
....
}
This seems to have sped things up a bit without any errors so far as far as I can tell.But is this safe?Does using a applicationwide static EntityConnection introduce race conditions?
View 3 Replies
Dec 26, 2010
i want to create a dropdown control in which i want to bind data from my webservice, i know i have to create a custom server control with inherrit the System.Web.UI.WebControls.DropDownList in my class.
my problem is that i dont know how to bind data(say a datatable dt) from dt and further disable the datasource property and item.insert property so that no other data could be enter in this control.
View 3 Replies
Sep 22, 2010
We have an application gathering counter statistics and we would like the values to reset after executing the iisreset command and that's all.
Microsoft says Application_Start is:
Called when the first resource (such as a page) in an ASP.NET application is requested. The Application_Start method is called only one time during the life cycle of an application. You can use this method to perform startup tasks such as loading data into the cache and initializing static values.
This is how we're currently doing it:
protected void Application_Start(object sender, EventArgs e)
{
_counters.Get<AutoCounter>("TAS:RequestCount").Reset();
_counters.Get<AutoCounter>("TAS:RequestTime").Reset();
_counters.Get<AutoCounter>("TAS:TimeBetweenErrors").Reset();
_counters.Get<AutoCounter>("TAS:ErrorCount").Reset();
}
However, these are resetting at unexpected intervals. What determines when the application domain's life-cycle ends and this method is called on the next request?
View 2 Replies
Aug 5, 2010
Question: When a webapplication gets started, it executes Application_Start in global.asax.Now, a web application gets started as soon as the first request for a page in that application reaches the server.But my question is: how long will the application run until the application is stopped.I mean when after the first page request, there's no traffic on the server.I need to know because I intend to start a server that listens on a tcp port in global.asax.And when the application stops, the server ceases to listen to its port.
View 2 Replies
Apr 28, 2010
I have the following generic lifetime manager
[code]...
causes the following error
Cannot create an instance of UI.Common.Unity.RequestLifetimeManager`1[T] because Type.ContainsGenericParameters is true.How do you reference generic lifetime managers?
View 1 Replies
Mar 22, 2011
How can I get the file creation date of the file used in the FileUpload control?
View 3 Replies
Feb 6, 2010
vs asp2008 instance cant recognize the sqlExpress 2008 instance on my machine
I have wonder if you could try to help me with the fallowing issue:When trying to add a new sql server connection (local or remount) from VS(visual studio) 2008 express - on the add connection dialog
box: server name: are Empty!!
The vs couldn't point to any database, like dont recognize the sqlExpress 2008 instance i got on my machine.
1. Have tried to "play" with sa property's(from sqlS: Databases: security: login tree folder) and with the sql
s windows service: stop and restart
2. And so with the target db.
3.
On the services.msc
The sql server express the status is started.
The sql server agent status is disabled and don't have the option to start.
The sql server explorer status is disabled and don't have the option to start.
4. And so reinstalled the asp.
View 2 Replies
Feb 17, 2011
I am trying to assign user control from another user control ..first time its binding control successfully but when we refresh the data its giving error
saying "Object reference is not set an instance".
how to refresh data from another user control ...
My senerio below :
1 Aspx page
2. User control
calling usercontrol databinding method from aspx page but once it get refreshed ,not allowed to bind it again..
View 2 Replies
Oct 20, 2010
How can I create an instance of a web control at runtime using reflection? I created a series of controls that implement a common interface and I would like to create these controls based on the name of the control which is stored in my database.
I have attempted (and failed) to create an instance of these controls using Activator.CreateInstance in the following ways:
Activator.CreateInstance("MyUserControl")
and
Activator.CreateInstance("ASP","controls_myusercontrol_ascx")
...and both return null.
I've also attempted to simply get the type of the control by trying..
Type t = Type.GetType("controls_myusercontrol_ascx");
and
Type t = Type.GetType("MyUserControl");
...and it returns null.
If I explicitly declare an object as controls_myusercontrol_ascx or MyUserControl, there is no issue -- but it can't be found with reflection.
Is it possible to create web user controls using reflection at run time? If so, how can I?
View 1 Replies
Jan 20, 2010
Is there a quick way to get the instance by Dom element.
My way is:
Base.find = function(element)
{
var c = Sys.Application.getComponents();
for (var i = 0; i < c.length; i++)
{
var e = c[i].get_element();
if (e == element)
return c[i];
}
return null;
}
View 3 Replies
Nov 29, 2010
I have a user control that has multiple instances on a single page.
Is it possible to have each instance use a unique ValidationGroup? I could expose a property, but I'm wondering if there's any way to do it automatically.
View 3 Replies
Jul 15, 2010
i am trying to enter a value into a texbox that is placed inside a user control called CollectionRequest. i have referenced this user control in my code behind and created an instance of it but i seem to get the above error when i try to enter some manual text. code as follows:
protected CollectionRequest collReq;
protected void Page_Load( object sender, EventArgs e )
{
collReq = (CollectionRequest)LoadControl("~/CollectionRequest.ascx");
TextBox _txt_address = (TextBox)collReq.FindControl("txt_Address");
_txt_address.Text = "thisi is an address";
control has been referenced in source file
<%@ Reference Control="~/CollectionRequest.ascx"%>
i am caling this code in my Approval.ascx.cs code. both the user controls are displayed together in the default.aspx page one above the other.
View 11 Replies
Jul 28, 2010
I have this Web User Control, with 3 controls:
[Code]....
In code behind:
[Code]....
When I try to add two UserControl and I Click in btnSearch of second UserControl, txtSearch.txt returns value of first User control.
How I can get the value of second txtSearch?
View 3 Replies
Nov 21, 2010
I'm trying to unit test the MembershipProvider, however I cant figure out how or whether there is any need for unit testing of it...
My business layer:
public interface IAccountService
{
MembershipCreateStatus CreateUser(string userName, string password, string email);
}
public class AccountService : IAccountService
{
private readonly MembershipProvider provider;
public AccountService() : this(null) { }
public AccountService(MembershipProvider providera)
{
this.provider = providera ?? Membership.Provider;
}
public MembershipCreateStatus CreateUser(string userName, string password, string email)
{
if (String.IsNullOrEmpty(userName)) throw new ArgumentException("Value cannot be null or empty.", userName);
if (String.IsNullOrEmpty(password)) throw new ArgumentException("Value cannot be null or empty.", password);
if (String.IsNullOrEmpty(email)) throw new ArgumentException("Value cannot be null or empty.", email);
MembershipCreateStatus status;
provider.CreateUser(userName, password, email, null, null, true, null, out status);
return status;
}
}
The only examples I've found so far requires a "MockMembershipProvider" with a local database setup... seems quite odd to me.
View 1 Replies
Jan 7, 2010
I'm working on an ASP.NET solution with 2 projects. One is the web interface and the other contains my business logic. I'm using LINQ to SQL for my data access in the second project.
Apart of my database, I have a table called Users which holds user information.
I've started to implement a MembershipProvider. I notice that MembershipUser is coupled with MembershipProvider. What is the most correct way of getting my BLL/DAL to talk about Users?
Should I minimally implement MembershipUser and whenever a user calls a method, it will call for eg. GetUserInfo() in my BLL/DAL, to get complete information about the user?
Or should I make the MembershipUser class methods call my custom "Users" class methods (like a wrapper) in the BLL/DAL (this custom users class is not related to linq)?
Or can I somehow extend the Linq to sql class "CFUsers" to extend MembershipUser.
View 1 Replies
Apr 2, 2010
I have an C# asp.net app using the default Sql MembershipProvider. My web.config has a few settings that control how I'm using this Provider:
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresUniqueEmail="true"
passwordFormat="Hashed"
minRequiredPasswordLength="5"
The problem I'm running into is that when people reset their passwords, it seems the ResetPassword() method returns a password that is longer than I want and has characters that can be confusing (l,1,i,I,0,O). Furthermore, I'm sending my users an email with a plain-text message and an HTML message (I'm using MailMessage with AlternateViews). If the password has unsafe HTML characters in it, when the email clients render the HTML text the password might be different (e.g. the %, &, and < aren't exactly HTML safe).
I've looked over the "add" element that belongs in the web.config, but I don't see any extra configuration properties to only include certain characters in the ResetPassword() method and to limit the password length.
Can I configure the ResetPassword() method to limit the password length and limit the character set it is choosing from?
Right now I have a workaround: I call ResetPassword() to make sure the supplied answer is correct, and then I use a RandomPassword generator I downloaded off the internet to generate a password that I like (without ambiguous characters, HTML safe, and only 8 characters long) and then I call ChangePassword() to change the user's password after I've already reset it.
View 3 Replies
Dec 1, 2010
We are converting an ASP site (using DotNetNuke) to a new PHP site. The only thing we have right now is a full export of the existing database. One of the tables is called "aspnet_Membership" and contains the following fields:
Password (looks like base64)
PasswordFormat (always value 2)
PasswordSalt (looks like base64)
PasswordQuestion (always empty)
PasswordAnswer (always empty)
We would like to decode these passwords and hash them to fit our own framework. From what I understand from the .NET documentation these kind of passwords can be decrypted. Is there an algorithm available that can do this or is it more complicated than that? Will it be possible if we create an ASP script on the current server?
View 2 Replies
Aug 5, 2010
Within a controller action, how do I get a reference to the current MembershipProvider? That would be the one specified in web.config as the default provider. I newed up an AccountMembershipService object, but it does not expose the _provider within it.I am not entirely clear on what I want. I want to create a site user in code and then store the UserId as a foreign key in the vendor master of my application. To do that I am thinking I can add a method to my custom membership provider that creates a user and returns the ID of that new user. What I need is be able to get a reference to the custom membership provider in the controller action method.
View 1 Replies
Nov 12, 2010
i have a class library for membership provider and inherits from System.Web.Security.sqlMembershipProvider
i just want to change somthing in it this class library will work in difrent web form application
i need to get the connectionStringName in web.config where the membership set to work with it.
how can i get the connectionStringName?
View 3 Replies