asp.net用户登录但返回登录页面

时间:2016-03-19 15:59:51

标签: c# asp.net security

我希望有人能在这里给我一个正确的方向。我正在使用Visual Studios 2015社区版。

我的Login.aspx页面位于“帐户”文件夹中。我在Account文件夹中的web.config文件如下所示;

<?xml version="1.0"?>
<configuration>

<location path="Manage.aspx">
<system.web>
  <authorization>
    <deny users="?"/>
  </authorization>
</system.web>
</location>

<location path="Home.aspx">
<system.web>
  <authorization>
    <deny users="?"/> 
  </authorization>
</system.web>
</location>
<location path="Home">
<system.web>
  <authorization> 
    <deny users="?"/>  
  </authorization>
</system.web>
</location>

</configuration>

我在Account文件夹中也有一个Home.aspx文件。当我直接导航到Home.aspx文件时,我按预期重定向到登录页面。如果我登录,我可以看到我登录为Site.Master模板逻辑欢迎我。但是,我没有重定向到Home.aspx站点,但仍保留在登录页面。

我可以看到url字符串中的returnurl值似乎试图导航到正确的页面。

http://localhost:63960/Account/Login?ReturnUrl=%2fAccount%2fHome.aspx

但是,我仍然在登录页面。

根文件夹中的我的web.config如下所示;

<?xml version="1.0" encoding="utf-8"?>

<configuration>
<configSections>

</configSections>
<connectionStrings>
<add name="EventDBContext" connectionString="Data Source=.;Initial Catalog=SampleDB;Integrated Security=True;" providerName="System.Data.SqlClient"/>
<add name="ApplicationServices" connectionString="Data Source=.;Initial Catalog=SampleDB;Integrated Security=True;" providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<authentication mode="Forms">
  <forms loginUrl="~/Account/Login.aspx" timeout="2880" />
</authentication>
<compilation debug="true" targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.2" />
<pages>
  <namespaces>
    <add namespace="System.Web.Optimization" />
    <add namespace="Microsoft.AspNet.Identity" />
  </namespaces>
  <controls>
    <add assembly="Microsoft.AspNet.Web.Optimization.WebForms" namespace="Microsoft.AspNet.Web.Optimization.WebForms" tagPrefix="webopt" />
  </controls>
  </pages>
  <membership>
  <providers>
    <clear />
    <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
  </providers>
 </membership>
 <profile>
  <providers>
    <clear />
    <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/" />
  </providers>
  </profile>
  <roleManager enabled="true">

  <providers>
    <clear />
    <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" />
    <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />

  </providers>
  </roleManager>

  <sessionState mode="InProc" customProvider="DefaultSessionProvider">
  <providers>
    <add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31xxxxxxxe35" connectionStringName="DefaultConnection" />
  </providers>
  </sessionState>
  <httpModules>
  <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" />
  </httpModules>
  </system.web>
  <system.webServer>
  <modules>

  <remove name="ApplicationInsightsWebTracking" />
  <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler" />
  </modules>
  <validation validateIntegratedModeConfiguration="false" />
 </system.webServer>
 <runtime>
 <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  <dependentAssembly>
    <assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30xxxxxxed" />
    <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="WebGrease" culture="neutral" publicKeyToken="31xxxxxxxe35" />
    <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="EntityFramework" publicKeyToken="b77xxxxx89" />
    <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="Microsoft.Owin" culture="neutral" publicKeyToken="31xxxxxxxe35" />
    <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="Microsoft.Owin.Security.OAuth" culture="neutral" publicKeyToken="31xxxxxxxe35" />
    <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="Microsoft.Owin.Security.Cookies" culture="neutral" publicKeyToken="31xxxxxxxe35" />
    <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="Microsoft.Owin.Security" culture="neutral" publicKeyToken="31xxxxxxxe35" />
    <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
  </dependentAssembly>
  </assemblyBinding>
 </runtime>
 <system.codedom>
 <compilers>
  <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31xxxxxxxe35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701" />
  <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31xxxxxxxe35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
</compilers>
</system.codedom>
</configuration>

非常感谢任何指导。

1 个答案:

答案 0 :(得分:0)

我想出了我的问题。我正在将以前的表单身份验证方法与asp.net身份方法混合使用。

我没有将所有内容转换为Identity方法,一切正常。

相关问题