Web Forms :: Disposing Of A Custom Defined Membership ?
Apr 13, 2010
I am writing here because I want to find out if there is a way of disposing of a custom defined membership asp.net provider within an application?If I make my custom provider disposable can I access it from the code-behind or is there an option which says the provider to be disposed?
This is my first membership provider; I converted the sample provider [URL] to SQL. I created a vb class provider and put it into the App_Code folder. After it was created I tried to modify my webconfig but the error pops up. I don't know what else to try, I don't know if I have missed something
I have to use inline code for an aspx page and I need to use a custom server control that is defined in the same aspx page but the control does not get processed as a server control. it gets returned as is as static html tag.
I create custom principal for implement logic for users. In identity I store Id, Name. But it abnormally - this classes must use for authenticate and authorize.
I can implement custom MembershipUser, custom Roles and Membership provider.
I'm new to ASP.NET and I don't exactly understand some features.
I have a custom membership provider TestMembershipProvider which inherits from MembershipProvider. It has the following CreateUser method:
[Code]....
It's absolutely simple code.Then I have two text boxes (login, password) and the button to register a new user. I thas a following code:
[Code]....
[Code]....
Authentication in web.config is set like this:
[Code]....
No matter what I write into textboxes, following error is being returned:
The password retrieval question provided is invalid.
I don't know why. Either in web.config or in get RequiresQuestionAndAnswer I have false value. When I instantiate my TestMembershipProvider and call CreateUser directly instead of using static Membership.CreateUser, it works fine. Do I have to use instance of my TestMembershipProvider or did I missed anything?
I have created my custom MembershipProvider. I have used an instance of the class DBConnect within this provider to handle database functions. Please look at the code below:
public class SGIMembershipProvider : MembershipProvider { #region "[ Property Variables ]" private int newPasswordLength = 8; private string connectionString; private string applicationName; private bool enablePasswordReset; private bool enablePasswordRetrieval; private bool requiresQuestionAndAnswer; private bool requiresUniqueEmail; private int maxInvalidPasswordAttempts; private int passwordAttemptWindow; private MembershipPasswordFormat passwordFormat; private int minRequiredNonAlphanumericCharacters; private int minRequiredPasswordLength; private string passwordStrengthRegularExpression; private MachineKeySection machineKey; **private DBConnect dbConn;** #endregion ....... public override bool ChangePassword(string username, string oldPassword, string newPassword) { if (!ValidateUser(username, oldPassword)) return false; ValidatePasswordEventArgs args = new ValidatePasswordEventArgs(username, newPassword, true); OnValidatingPassword(args); if (args.Cancel) { if (args.FailureInformation != null) { throw args.FailureInformation; } else { throw new Exception("Change password canceled due to new password validation failure."); } } SqlParameter[] p = new SqlParameter[3]; p[0] = new SqlParameter("@applicationName", applicationName); p[1] = new SqlParameter("@username", username); p[2] = new SqlParameter("@password", EncodePassword(newPassword)); bool retval = **dbConn.ExecuteSP("User_ChangePassword", p);** return retval; } //ChangePassword public override void Initialize(string name, NameValueCollection config) { if (config == null) { throw new ArgumentNullException("config"); } ...... ConnectionStringSettings ConnectionStringSettings = ConfigurationManager.ConnectionStrings[config["connectionStringName"]]; if ((ConnectionStringSettings == null) || (ConnectionStringSettings.ConnectionString.Trim() == String.Empty)) { throw new ProviderException("Connection string cannot be blank."); } connectionString = ConnectionStringSettings.ConnectionString; **dbConn = new DBConnect(connectionString); dbConn.ConnectToDB();** ...... } //Initialize ...... } // SGIMembershipProvider
I have instantiated dbConn object within Initialize() event. My problem is that how could i dispose off this object when object of SGIMembershipProvider is disposed off. I know the GC will do this all for me, but I need to explicitly dispose off that object. Even I tried to override Finalize() but there is no such overridable method. I have also tried to create destructor for SGIMembershipProvider.
Dim req as httprequest ip = req.servervariables("remote_host") 'result = nothing Dim req as new httprequest ip = req.servervariables("remote_host") 'result = nothing Dim req as requestcontext ip = req.request.servervariables("remote_host") 'result = nothing...
<uc:MyControl ...> <Template> </Template> </uc:Mycontrol> I would like <uc:MyControl ...> <FishBiscuit> html </FishBiscuit> <FishBiscuit> html </FishBiscuit> <FishBiscuit> html </FishBiscuit> <FishBiscuit> html </FishBiscuit>
However I'm not sure if it's possible, or how to wire it up if it is.
Unfortunately, all the examples for Forms Authentication Code Behind w/ Custom Role and Membership Providers I find online are written with a VB.NET code behind and I need a C# code behind. I need a codebehind that will do the following:
authenticate user upon login button click if user active_flag=0 (false) OR password!=@password, display error: "Access Denied" if user admin_flag=1 & active flag=1 (true), redirect to admin_pageszipsearch.aspx if user admin_flag=0 (false) & active_flag=1 (true), redirect to pageszipsearch.aspx
What is the best practice on disposing objects in a .net method? I tend to avoid try/catch blocks as much as possible, so lets say I have a method in vb.net code behind that instantiates an object (The object may be a local variable or a class variable).Should I call objectName.dispose() when I am done with it?I am keeping in mind that I should aquire the object late and release it early during that method execution.
Private Sub Entity_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init im db As New LinqDataAccess.QuantumDataContext Dim result = db.GetAddressType("Company") [code]...
I want to write own control which can contain other. And I want to define content of the control in the .aspx file where the control is defined. I have written such control. But now I have issue with ViewState of inner controls of my control. The following samle illustrates the issue: I defined two asp:DropDownList ID="ddl1" and ID="ddl2" One of them is inside of my control and other is outside. When posback is occurred asp:DropDownList ID="ddl1 loses state and becomes empty. How to say ASP.net to store state of inner controls defined by this way?
MyControl.ascx:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="MyControl.ascx.cs" Inherits="DynamicControls.Controls.MyControl" %>
I recently got a form to work with the "HttpContext.Current.User.Identity.Name.ToString" String. That basic idea was I needed a hidden form field so that each record submitted would include the UserName of the user logged in to the membership. However, whenever I try to create a custom query for the gridview, it doesn't submit. how I would go about doing this? Code as below:
I have a CustomRequestContext object that has to be disposed after each request. I create it in Page_Load and dispose of it in Page_Unload. The only issue is that in certain circumstances I need to call Server.Transfer to redirect to another aspx page instead. In this case, the object should not be unloaded until the new page is ready to be unloaded. What is the nicest way of achieving this?
i am planing an application that needs to handle different client logins. A user should be able to login under each clients url.The project will have a start page and multiple (database generated) client URLs.www.domain.com/ClientA www.domain.com/ClientB www.domain.com/ClientC I failed using MVC Routes to build up such a scenario with dynamically clients so i used an MVC area for the client space:www.domain.com/clients/ClientA www.domain.com/clients/ClientB www.domain.com/clients/ClientC Is there any client support for membership providers? All i found is made for a single client environment. I would love to take advantage of the mvc buildin attributes for authentication..
I have an UpdatePanel that contains several "items" that are in individual divs that are registered as dragdrop objects. I pass the item ID into the object. Everything appears to be working fine until I delete an item/div. The items appear in the correct divs but the ID's are mismatched as if the delete never happened. I know the dispose method is being called for each object. But I don't know how the deleted item ID is still being passed in a drag/drop object that should be re-initialized on every pageLoad. It's difficult to explain but here is some of the relevant code:
When is the LastActivityDate supposed to be updated? When I click on any other pages in my web application as an authenticated user, the LastActivityDate does not get updated.
I would imagine it should be updated when a user clicks on any page, whether it be to do with membership (change password, GetUser(), etc) or not. But the examples that I have seen, seem only to update it on ValidateUser().
Now this might just be straightforward, but I can't seem to figure it out..
I have set up the Custom Membership provider, and gave it the proper connection stuff. What I know is that it connects to the correct database, but I know for sure that it doesn't look at the correct table.
How would I set it up to use a specific table? As the table already has users in them.
The table name is: members_info.
the column names are: member___id(key), member_name, member__pwd, member_perm
member___id => Being the Key and the account name to login with member_name => Being the users Name or Nickname member__pwd => 10 chars long (for now) member_perm => holds 1 of the following values: 0) User 1)Admin 2)Banned
now I know that the later one is to be setup by the Role Provider, and I'm sure once I know how to do the membership one that one is similar in some way.
So my question is, how do I point the Custom Membership Provider to the table: members_info and to use member___id for username, members__pwd for password (and possibly get member_name out to say: Welcome {member_name}! when they login).
===
Added info. Members__uid is the key value as it increases on each new entry.
===
Since you can't tell it to use a specific table
How can I set it up so, that it works with the tool provided in visual studio? (Website > ASP.net Configuration).
As it now says 0 users, on the security tab. I want to be able to manage the users through here too.
thisUser gives me access to all the fields in aspnet_Membership. I want a new field, isSubscribed for each user. I can use an SQL query to fetch the value fine, but I want to know if there is someway to modify the membershipuser object so it retrieves this value as well, so it is accessible from:
I have a custom membership project for my asp .net website and I want to use a few custom variables for use in the ValidateUser function, can I set these somewhere like in the OnLoggingIn method of the Login Control?
i'm new to the mvc framework but i used forms authentification in an asp.net webapplication. Because im forced to use Sybase SQL Anywhere server i use membership / profile / role provider from sybase.Why i can't login in the MVC Application? When i create a user via mvc web control i'm logged in. But when i logout and try to login i get a error that username or password is not correct.Maybe someone has an idea? Could it be a problem with the application name? Both have the applicationname " / " ?Both applications has these web.config entries: