Hi Mohammad!
Thansk for you quick reply
Yes I use custome membership provider. I use project model and I have
created "ASP .NET MVC" project through its template (1.0). It is a
local server, I have used the built in SQL Server in VS 2008.

my wb.config for mentioned part (nhibernate and membership provider
looks like so:

_________________ Parts of web.config _________________

<configuration>

  <configSections>
   ....
    <section name="hibernate-configuration"
type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" />
  </configSections>

  <appSettings/>

  <connectionStrings>
    <add name="ApplicationServices" connectionString="data source=.
\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|
aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient"/
>
  </connectionStrings>

  <system.web>
...
    <authentication mode="Forms">
      <forms loginUrl="~/Account/LogOn" timeout="2880" />
    </authentication>

    <membership defaultProvider="MonitorMembershipProvider">
      <providers>
        <clear/>
        <add name="MonitorMembershipProvider"
 
type="WebMonitorUpdate.MembershipServicesImpl.SQLServerMembershipProvider"
             connectionStringName=""
             enablePasswordRetrieval="true"
             enablePasswordReset="true"
             requiresQuestionAndAnswer="false"
             requiresUniqueEmail="true"
             passwordFormat="Hashed"
             maxInvalidPasswordAttempts="5"
             minRequiredPasswordLength="6"
             minRequiredNonalphanumericCharacters="0"
             passwordAttemptWindow="10"
             passwordStrengthRegularExpression=""
             applicationName="/"
                />
      </providers>
    </membership>

    <profile>
      <providers>
        <clear/>
        <add name="AspNetSqlProfileProvider"
             type="System.Web.Profile.SqlProfileProvider, System.Web,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
             connectionStringName="ApplicationServices"
             applicationName="/"
                />
      </providers>
    </profile>

    <roleManager enabled="false">
      <providers>
        <clear />
        <add connectionStringName="ApplicationServices"
applicationName="/" name="AspNetSqlRoleProvider"
type="System.Web.Security.SqlRoleProvider, System.Web,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
        <add applicationName="/" name="AspNetWindowsTokenRoleProvider"
type="System.Web.Security.WindowsTokenRoleProvider, System.Web,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
      </providers>
    </roleManager>

   .....

  <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
    <session-factory name="WebMonitorUpdate">
      <property
name="connection.provider">NHibernate.Connection.DriverConnectionProvider</
property>
      <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</
property>
      <property
name="connection.driver_class">NHibernate.Driver.SqlClientDriver</
property>
      <property name="connection.connection_string">Data Source=.
\SQLEXPRESS;AttachDbFilename=|DataDirectory|
WebMonitorUpdate.mdf;Integrated Security=True;User Instance=True</
property>
      <property
name="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory,
NHibernate.ByteCode.LinFu</property>
      <mapping assembly ="WebMonitorUpdate" />
    </session-factory>
  </hibernate-configuration>
</configuration>
___________________________________________________


Here is the code for my membership provider:

_________________ MEMBERSHIP PROVIDER _________________

    public sealed class SQLServerMembershipProvider :
MembershipProvider
    {
        private OnlineSystemService service = null;

        private string applicationName;
        private int maxInvalidPasswordAttempts;
        private int passwordAttemptWindow;
        private int minRequiredNonAlphanumericCharacters;
        private int minRequiredPasswordLength;
        private string passwordStrengthRegularExpression;
        private bool enablePasswordReset;
        private bool enablePasswordRetrieval;
        private bool requiresQuestionAndAnswer;
        private bool requiresUniqueEmail;

        #region Settings

        public override string ApplicationName
        {
            get { return this.applicationName; }
            set { this.applicationName = value; }
        }

        public override int MaxInvalidPasswordAttempts { get { return
this.maxInvalidPasswordAttempts; } }
        public override int PasswordAttemptWindow { get { return
this.passwordAttemptWindow; } }
        public override int MinRequiredNonAlphanumericCharacters { get
{ return this.minRequiredNonAlphanumericCharacters; } }
        public override int MinRequiredPasswordLength { get { return
this.minRequiredPasswordLength; } }
        public override string PasswordStrengthRegularExpression { get
{ return this.passwordStrengthRegularExpression; } }
        public override bool EnablePasswordReset { get { return
this.enablePasswordReset; } }
        public override bool EnablePasswordRetrieval { get { return
false; } }
        public override bool RequiresQuestionAndAnswer { get { return
this.requiresQuestionAndAnswer; } }
        public override bool RequiresUniqueEmail { get { return
this.requiresUniqueEmail; } }
        public override MembershipPasswordFormat PasswordFormat
        {
            get { return MembershipPasswordFormat.Hashed; }
        }

        #endregion

        public SQLServerMembershipProvider(): this(null)
        {
        }

        public SQLServerMembershipProvider(OnlineSystemService
service)
        {
            this.service = service ?? new OnlineSystemService();
        }

        public override void Initialize(string name,
NameValueCollection config)
        {
            base.Initialize(name, config);

            this.ApplicationName = GetConfigValue(config
["applicationName"],
 
System.Web.Hosting.HostingEnvironment.ApplicationVirtualPath);
            this.maxInvalidPasswordAttempts = Convert.ToInt32
(GetConfigValue(config["maxInvalidPasswordAttempts"], "5"));
            this.passwordAttemptWindow = Convert.ToInt32(GetConfigValue
(config["passwordAttemptWindow"], "10"));
            this.minRequiredNonAlphanumericCharacters = Convert.ToInt32
(GetConfigValue(config["minRequiredNonAlphanumericCharacters"], "1"));
            this.minRequiredPasswordLength = Convert.ToInt32
(GetConfigValue(config["minRequiredPasswordLength"], "7"));
            this.passwordStrengthRegularExpression = Convert.ToString
(GetConfigValue(config["passwordStrengthRegularExpression"],
string.Empty));
            this.enablePasswordReset = Convert.ToBoolean(GetConfigValue
(config["enablePasswordReset"], "true"));
            this.enablePasswordRetrieval = Convert.ToBoolean
(GetConfigValue(config["enablePasswordRetrieval"], "true"));
            this.requiresQuestionAndAnswer = Convert.ToBoolean
(GetConfigValue(config["requiresQuestionAndAnswer"], "false"));
            this.requiresUniqueEmail = Convert.ToBoolean(GetConfigValue
(config["requiresUniqueEmail"], "true"));
        }

        public override bool ChangePassword(string username, string
oldPassword, string newPassword)
        {

            //username and systemId1 are splited by |
            if (!String.IsNullOrEmpty(username))
            {
                OnlineSystem system =
this.service.getCustomerInfoByName(username);
                if (system == null) return false;

                if (!CheckPassword(oldPassword, system.Password))
return false;

                ValidatePasswordEventArgs args = new
ValidatePasswordEventArgs(username, newPassword, false);
                OnValidatingPassword(args);
                if (args.Cancel)
                {
                    if (args.FailureInformation != null)
                        throw args.FailureInformation;
                    else
                        throw new MembershipPasswordException("Change
password canceled due to new password validation failure.");
                }
                system.Password = HashPassword(newPassword);
                service.SystemDAO.commitTransaction();
            }
            else
            {
                return false;
            }
            return true;
        }
        /*
         * This method check whether the username/system ID and
password match together for a user!
         */
        public override bool ValidateUser(string usernameAndSystemId,
string password)
        {
            string[] temp = usernameAndSystemId.Split('|');
            string username = temp[0];
            int systemId;
            if (!String.IsNullOrEmpty(temp[1]) && int.TryParse(temp
[1], out systemId) && !String.IsNullOrEmpty(username))
            {
                OnlineSystem system =
this.service.getCustomerInfoByName(username);
                if (system == null) return false;

                if (!CheckPassword(password, system.Password) ||
system.SS20Id != systemId) return false;

                return true;
            }
            else
            {
                return false;
            }
        }

        /*
         * Since the login process need username and system id GetUser
should be overrde!
         * if user is online the information should be pass otherwise
not.
         */
        public override MembershipUser GetUser(string username, bool
userIsOnline)
        {
            MembershipUser user = null;

            if (!String.IsNullOrEmpty(username) && userIsOnline)
            {
                OnlineSystem system =
this.service.getCustomerInfoByName(username);
                if (system != null)
                {
                    user = new MonitorUser(this.Name,
                                        system.LoginName,
                                        system.SS20Id,
                                        string.Empty,
                                        string.Empty,
                                        string.Empty,
                                        true,
                                        false,
                                        DateTime.MinValue,
                                        DateTime.MinValue,
                                        DateTime.MinValue,
                                        DateTime.MinValue,
                                        DateTime.MinValue,
                                        system);
                }
            }
            return user;
        }


        //Removed other methods, I do not have override other method
since I do not need them

        #region Helper Methods

        private bool CheckPassword(string password, string dbpassword)
        {
            return BCrypt.CheckPassword(password, dbpassword);
        }

        private string HashPassword(string password)
        {
            return BCrypt.HashPassword(password, BCrypt.GenerateSalt
(10));
        }

        private string GetConfigValue(string configValue, string
defaultValue)
        {
            if (String.IsNullOrEmpty(configValue))
                return defaultValue;

            return configValue;
        }

        #endregion

__________________________________________________________

Hope this information is good enough.

The other problem I guess which can be the reason, is the initialize
method in my membership provider. It does not run at all when I trace
the code in debug mode.

Thanks in advance for your help.

Regards
Sheri


On 12 Jan, 09:26, Mohamed Meligy <[email protected]> wrote:
> I think there needs to be more information on this.
> Do you use a custom membership provider that uses NH entities in any way?
> Are you using Website model or Web Application Project model?
> Is this problem on local server or remote?
> Can you post any code samples you believe are relevant?
>
> Regards,
>
> --
> Mohamed Meligy
> Senior Developer, Team Lead Backup (.Net Technologies - TDG - Applications)
> Injazat Data Systems
> P.O. Box: 8230 Abu Dhabi, UAE.
>
> Phone:  +971 2 6992700
> Direct:   +971 2 4045385
> Mobile:  +971 50 2623624, +971 55 2017 621
>
> E-mail: [email protected]
> Weblog:http://weblogs.asp.net/meligy
>
>
>
> On Tue, Jan 12, 2010 at 12:13 PM, Sheri <[email protected]> wrote:
> > Hi!
> > I have an application which is developed in "ASP .NET MVC". I use
> > NHibernate. and my IDE is VS 2008. Until yesterday I could use
> > NHibernate and "Membership Provider" alltogether. But today they do
> > not work and I get error. Could anybody help me please.
>
> > The reason I have got: when I change my hbm.xml files build action
> > properties to "Embedded Resource" which they should be so, I get this
> > problem.
> > Here is the error I get:
> > _______________________________________________
>
> > Server Error in application program
> > Configuration error
>
> > Description: An error occurred during the processing of a
> > configuration file required to service this request. Please review the
> > specific error details below and modify your configuration file
> > appropriately.
>
> > Parser Error Message: "An Exception has Occurred in the case of
> > Activation"
> > --------------------------------------------------
> > ------------------------------
> > Row 67:         <clear/>
> > Row 68:         <add name="SQLServerMembershipProvider"
> > Row 69:
> > type="WebMonitorUpdate.MembershipServicesImpl.SQLServerMembershipProvider"
> > Row 70:              connectionStringName=""
> > Row 71:              enablePasswordRetrieval="true"
>
> > file: C:\Projects\WebMonitorUpdate\WebMonitorUpdate\web.config    Row:
> > 69
>
> > --------------------------------------------------
> > ------------------------------
> > Version Information: Microsoft. NET Framework Version: 2.0.50727.4200;
> > ASP.NET Version: 2.0.50727.4016
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "nhusers" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to
> > [email protected]<nhusers%[email protected] 
> > >
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/nhusers?hl=en.
-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.


Reply via email to