none
Dúvida com autenticação Membership RRS feed

  • Pergunta

  • Pessoal, Boa Tarde!!

    Uma pequena dúvida referente a autenticação no membership. Eu criei uma página de Login, mas quando ele autentica ele não manda pra página inicial. A grande dúvida é onde eu aponto qual página ele deve enviar após a validação do usuário.

    Segue meu codebehind e web.config da parte da autenticação:

     

    <?xml version="1.0"?>
    <configuration>
    	<configSections>
    		<sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
    			<sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
    				<section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
    				<sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
    					<section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere"/>
    					<section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
    					<section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
    					<section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
    				</sectionGroup>
    			</sectionGroup>
    		</sectionGroup>
    	</configSections>
    	<appSettings>
    		<add key="TITULO" value="TESTE"/>
    	</appSettings>
    	<connectionStrings>
    		<add name="CONEXAO" providerName="System.Data.SqlClient" connectionString="Server=Teste; Database=Teste; Uid=teste;Pwd=teste;"/>
    	</connectionStrings>
    	<system.web>
      <globalization requestEncoding="utf-8" responseEncoding="utf-8" culture="pt-br" uiCulture="pt-BR"/>
      <roleManager enabled="true" cacheRolesInCookie="true" cookieName=".ASPROLES" defaultProvider="SqlRoleProvider">
       <providers>
        <clear/>
        <add connectionStringName="CONEXAO" applicationName="Conponto" name="SqlRoleProvider" type="System.Web.Security.SqlRoleProvider"/>
       </providers>
      </roleManager>
      <membership defaultProvider="SqlMembershipProvider">
       <providers>
        <clear/>
        <add name="SqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="CONEXAO" applicationName="Conponto" enablePasswordRetrieval="true" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" passwordFormat="Clear" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="5" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" passwordStrengthRegularExpression=""/>
       </providers>
      </membership>
    		<compilation debug="true">
    			<assemblies>
    				<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
    				<add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
    				<add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    				<add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
    			</assemblies>
    		</compilation>
    		<authentication mode="Forms">
       <forms name="/.ASPROLES" loginUrl="Login.aspx" timeout="300" cookieless="UseCookies" protection="All"/>
      </authentication>
     
      <sessionState timeout="300"/>
      <customErrors mode="Off"/>
    		<pages>
    			<controls>
    				<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    				<add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        <add tagPrefix="cc1" namespace="AjaxControlToolkit" assembly="AjaxControlToolkit"/>
       </controls>
    		</pages>
      <siteMap>
       <providers>
        <add name="smpMenuCadastro" type="System.Web.XmlSiteMapProvider" siteMapFile="~/SiteMap/mnuCadastro.sitemap" securityTrimmingEnabled="false"/>
       </providers>
      </siteMap>
      <httpHandlers>
    			<remove verb="*" path="*.asmx"/>
    			<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    			<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    			<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>
    		</httpHandlers>
    		<httpModules>
    			<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    		</httpModules>
    	</system.web>
    	<system.codedom>
    		<compilers>
    			<compiler language="c#;cs;csharp" extension=".cs" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
    				<providerOption name="CompilerVersion" value="v3.5"/>
    				<providerOption name="WarnAsError" value="false"/>
    			</compiler>
    		</compilers>
    	</system.codedom>
    	<system.webServer>
    		<validation validateIntegratedModeConfiguration="false"/>
    		<modules>
    			<remove name="ScriptModule"/>
    			<add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    		</modules>
    		<handlers>
    			<remove name="WebServiceHandlerFactory-Integrated"/>
    			<remove name="ScriptHandlerFactory"/>
    			<remove name="ScriptHandlerFactoryAppServices"/>
    			<remove name="ScriptResource"/>
    			<add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    			<add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    			<add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    		</handlers>
    	</system.webServer>
    	<runtime>
    		<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    			<dependentAssembly>
    				<assemblyIdentity name="System.Web.Extensions" publicKeyToken="31bf3856ad364e35"/>
    				<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>
    			</dependentAssembly>
    			<dependentAssembly>
    				<assemblyIdentity name="System.Web.Extensions.Design" publicKeyToken="31bf3856ad364e35"/>
    				<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>
    			</dependentAssembly>
    		</assemblyBinding>
    	</runtime>
    </configuration>
    
    
    
    
    
    
     protected void lkbEntrar_Click(object sender, EventArgs e)
        {
          objConexao = new SqlConnection(CONEXAO);
          strSQL = "SPS_USUARIO";
          objComando = new SqlCommand(strSQL, objConexao);
          objComando.Parameters.AddWithValue("@DS_LOGIN", txtUsuario.Text.ToUpper());
    
          objComando.CommandType = CommandType.StoredProcedure;
    
          objConexao.Open();
    
          try
          {
            objDataReader = objComando.ExecuteReader();
    
            if (objDataReader.HasRows)
            {
              while (objDataReader.Read())
              {
                if (Membership.GetUser(txtUsuario.Text.ToUpper()).IsLockedOut)
                {
                  ScriptManager.RegisterClientScriptBlock(this, GetType(), "scriptAjax", "alert('Usuário bloqueado!');", true);
                }
                else if (Membership.ValidateUser(txtUsuario.Text.ToUpper(), txtSenha.Text.ToUpper()))
                {
                  FormsAuthentication.RedirectFromLoginPage(txtUsuario.Text.ToUpper(), true);
                }
                else
                {
                  ScriptManager.RegisterClientScriptBlock(this, GetType(), "scriptAjax", "alert('Senha incorreta!');", true);
                }
    
              }
    
            }
            else
            {
              ScriptManager.RegisterClientScriptBlock(this, GetType(), "scriptAjax", "alert('Usuário não existe!');", true);
            }
    
          }
          catch (Exception ex)
          {
            ScriptManager.RegisterClientScriptBlock(this, GetType(), "scriptAjax", "alert('Erro: '" + ex.Message.ToString() + "');", true);
          }
          finally
          {
            objConexao.Close();
            objComando.Dispose();
          }
    
        }
    
    
    
    
    

    System.NullReferenceException - Object reference not set to an instance of an object
    quarta-feira, 22 de setembro de 2010 18:53

Respostas

  • faltou o defaultpage no seu webconfig

    <authentication mode="Forms">
       <forms loginUrl="LoginFull.aspx" timeout="30" name=".ASPXAUTH" defaultUrl="Welcome.aspx" protection="All" slidingExpiration="true" />
      </authentication>
    • Marcado como Resposta Bruno Venturoza quinta-feira, 23 de setembro de 2010 13:44
    quinta-feira, 23 de setembro de 2010 12:25

Todas as Respostas

  • faltou o defaultpage no seu webconfig

    <authentication mode="Forms">
       <forms loginUrl="LoginFull.aspx" timeout="30" name=".ASPXAUTH" defaultUrl="Welcome.aspx" protection="All" slidingExpiration="true" />
      </authentication>
    • Marcado como Resposta Bruno Venturoza quinta-feira, 23 de setembro de 2010 13:44
    quinta-feira, 23 de setembro de 2010 12:25
  • Seilor, show de bola.

    Resolveu meu problema.

    Até peço desculpas por não ter visto a propriedade.

     

    Obrigado, abraços.


    System.NullReferenceException - Object reference not set to an instance of an object
    quinta-feira, 23 de setembro de 2010 13:44