表单身份验证:RedirectFromLoginPage始终重定向到登录页面,而不是默认页面

时间:2019-04-11 19:03:04

标签: c# webforms

我有一个使我发疯的问题。我已经对Google进行了广泛的研究,this site是信息最丰富的研究机构,但仍然找不到我的问题。

如果我未经身份验证直接输入Default.aspx,它会将我重定向到登录页面,就可以了。

我有一个简单的登录页面。我通过Web服务验证用户。如果Web服务返回10,则表示该用户存在,然后我调用FormsAuthentication.RedirectFromLoginPage以显示Default.aspx。

我在网络上尝试了一些建议,但无济于事。当我调用FormsAuthentication.RedirectFromLoginPage(txtUserName.text,true)时,它只是再次返回登录页面!

这是我的登录页面代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace CasesInterchange
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnIngresar_Click(object sender, EventArgs e)
        {
            var ws = new SyncService.SyncSoapClient();
            int isAuthenticated = ws.Authenticate(txtUsername.Text, txtPassword.Text, "");

            if (isAuthenticated == 10)
                FormsAuthentication.RedirectFromLoginPage(txtUsername.Text, true);
            else
                lblError.Visible = true;
        }
    }
}

这是我的web.config:

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  https://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
    <pages>
      <namespaces>
        <add namespace="System.Web.Optimization" />
      </namespaces>
      <controls>
        <add assembly="Microsoft.AspNet.Web.Optimization.WebForms" namespace="Microsoft.AspNet.Web.Optimization.WebForms" tagPrefix="webopt" />
      </controls>
    </pages>

    <authentication mode="Forms">
      <forms name="AuthCookie" loginUrl="LoginPage.aspx" defaultUrl="~/Default.aspx" protection="All" timeout="240" requireSSL="false" slidingExpiration="true" cookieless="UseDeviceProfile" enableCrossAppRedirects="true" domain="ssjsed1036" />
    </authentication>
    <authorization>
      <deny users="?"/>
    </authorization>
  </system.web>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
      <dependentAssembly>
        <assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" />
        <bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" />
        <bindingRedirect oldVersion="0.0.0.0-11.0.0.0" newVersion="11.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Diagnostics.DiagnosticSource" publicKeyToken="cc7b13ffcd2ddd51" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.2.1" newVersion="4.0.2.1" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930" />
      </dependentAssembly>      
    </assemblyBinding>
  </runtime>
  <system.webServer>
    <modules>
      <remove name="TelemetryCorrelationHttpModule" />
      <add name="TelemetryCorrelationHttpModule" type="Microsoft.AspNet.TelemetryCorrelation.TelemetryCorrelationHttpModule, Microsoft.AspNet.TelemetryCorrelation" preCondition="integratedMode,managedHandler" />
    </modules>
  </system.webServer>
  <system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 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=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
    </compilers>
  </system.codedom>

  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="SyncSoap" />
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://ssjsed1036/syncwebservice/sync.asmx"
        binding="basicHttpBinding" bindingConfiguration="SyncSoap" contract="SyncService.SyncSoap"
        name="SyncSoap" />
    </client>
  </system.serviceModel>
</configuration>

这似乎很简单,应该可以,但是不能。

请帮助!

谢谢!

0 个答案:

没有答案