用户始终保持未认证状态 [英] User always remains unauthentication

查看:78
本文介绍了用户始终保持未认证状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试进行表单身份验证,但可能是我的代码中的某些地方出了问题.即使成功登录,用户也总是未经身份验证:

在我的Web confing文件中,我有:

Im trying to do form authentication but probably some thing wrong is some where in my code.the user always reamins unauthenticated even after successful login in:

in my web confing file i have:

<<pre lang="xml">?xml version="1.0"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
    <connectionStrings>
        <add name="ADConnection" connectionString="LDAP://localhost:23766/WebSite21"/>
        <add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient"/>
        <add name="ConnectionString" connectionString="Data Source=FNUILTP10\SQL2005;Integrated Security=True" providerName="System.Data.SqlClient"/>
        <add name="ConnectionString2" connectionString="Data Source=FNUILTP10\SQL2005;Integrated Security=True" providerName="System.Data.SqlClient"/>
        <add name="RecordsManagementConnectionString" connectionString="Data Source=FNUILTP10\SQL2005;Initial Catalog=RecordsManagement;Integrated Security=True" providerName="System.Data.SqlClient"/>
    </connectionStrings>
    <system.web>
        <httpRuntime maxRequestLength="2097151" executionTimeout="360000"/>
        <compilation debug="true" targetFramework="4.0">
            <assemblies>
                <add assembly="System.DirectoryServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
                <add assembly="System.DirectoryServices.AccountManagement, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
                <add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
                <add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
                <add assembly="System.Web.Extensions.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
                <add assembly="Microsoft.Office.Tools.Word, Version=10.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
                <add assembly="Microsoft.Office.Tools.Excel, Version=10.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
                <add assembly="Microsoft.MSXML, Version=8.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/></assemblies></compilation>

        <authentication mode="Forms">
            <forms loginUrl="Login.aspx" protection="All" path="/" requireSSL="true" timeout="2880">
            </forms>
        </authentication>
        <identity impersonate="true"/>
        <authorization>
            <deny users="?"/>
        </authorization>

        <membership defaultProvider="MyADMembershipProvider">
            <providers>
                <add name="MyADMembershipProvider" type="System.Web.Security.ActiveDirectoryMembershipProvider,         System.Web, Version=2.0.0.0, Culture=neutral,         PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="ADConnection" attributeMapUsername="sAMAccountName"/>
            </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>
    </system.web>
    <system.webServer>
        <modules runAllManagedModulesForAllRequests="true"/>
    </system.webServer>

</configuration

>


并以以下一种网络形式:


and in one of the web forms:

protected void Page_Load(object sender, EventArgs e)
   {
       if (User.Identity.IsAuthenticated==false)
       {
           Response.Redirect("Login.aspx");
       }
}



即使提供正确的用户名和密码,它也总是返回登录页面...



It always returns to the login page even correct username and password is provided...

推荐答案

嘿,

我一眼就能看到两件事.
1.您已将用户模拟设置为true.因此,使用Forms身份验证,它总是尝试使用当前登录的用户登录(如果我没记错的话).尝试将其更改为false
2.为您的角色提供者和成员资格提供者提供一个应用程序名称.默认成员资格提供程序使用此名称来区分存储在同一数据库中的不同应用程序凭据.

试试这些,然后回到我们身边.祝你好运

问候
Hey there,

I can see 2 things at a glance.
1. You have set user impersonation true. So with Forms authentication, it is always trying to log you with the current logged-in user (if I am not mistaken). Try changing it to false
2. Provide an application name to your role provider and membership provider. Default membership providers use this name to differentiate between different application credentials stored in the same database.

Try these and get back to us. Good luck

Regards


这篇关于用户始终保持未认证状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆