奇怪的ASP.NET身份验证问题

时间:2013-05-22 15:47:27

标签: asp.net iis

我开发了一个.NET 4.0 ASP.NET网站。一切都在当地工作。 在IIS7.5上开发,WS2008R2 Enterprise +所有更新。

我部署到WS2003服务器。几乎所有工作除外,当我登录网站(Forms auth)时,它将我重定向回登录页面!没有错误,没有任何错误。 有时当我设法通过它,导航到另一个页面或执行像点击按钮的操作时,我会被重定向回登录页面!

确信服务器设置存在问题,IT人员安装了WS2008R2 +所有更新。很棒 - 所以我将网站部署到了那个。你猜怎么着?仍然存在同样的问题!

是什么给出的?为什么在您登录时(无代码执行此操作)或执行操作时,它会重定向回登录页面?

另一件事是,我正在使用Telerik控件以及ASP.NET AJAX扩展器。服务器似乎没有加载它们(服务器和客户端都没有错误)。应该有下拉菜单,除了要弹出的AJAX日历之外,它不起作用 - 这也不起作用。

我不知道现在该做什么,因为这令人沮丧,从来没有遇到过这样的问题。

这是我的配置文件的一部分:

<configSections>
    <sectionGroup name="system.web">
      <section name="sanitizer" requirePermission="false" type="AjaxControlToolkit.Sanitizer.ProviderSanitizerSection, AjaxControlToolkit"/>
    </sectionGroup>
  </configSections>

<system.web>
    <globalization culture="en-gb" uiCulture="en-gb"/>
    <httpRuntime maxRequestLength="100240"/>
    <trust level="Full"/>
    <sanitizer defaultProvider="HtmlAgilityPackSanitizerProvider">
      <providers>
        <add name="HtmlAgilityPackSanitizerProvider" type="AjaxControlToolkit.Sanitizer.HtmlAgilityPackSanitizerProvider"/>
      </providers>
    </sanitizer>
    <compilation debug="true" targetFramework="4.0">

      <assemblies>
        <add assembly="Telerik.Web.UI, Version=2012.3.1017.40, Culture=neutral, PublicKeyToken=949410a6b6ad1e71"/>
      </assemblies>
    </compilation>
    <sessionState mode="InProc" timeout="30"/>
    <authentication mode="Forms">
      <forms name="RegisteredUsers" defaultUrl="~/Help/About.aspx" path="/" protection="All" loginUrl="~/Account/Login.aspx" timeout="31"/>
    </authentication>
    <authorization>
      <deny users="?"/>
    </authorization>
    <httpHandlers>
    <add path="Telerik.Web.UI.WebResource.axd" type="Telerik.Web.UI.WebResource" verb="*" validate="false"/>
    </httpHandlers>
  </system.web>
  <location path="Account">
    <system.web>
      <authorization>
        <allow users="*"/>
      </authorization>
    </system.web>
  </location>
  <location path="Public">
    <system.web>
      <authorization>
        <allow users="*"/>
      </authorization>
    </system.web>
  </location>
  <location path="Styles">
    <system.web>
      <authorization>
        <allow users="*"/>
      </authorization>
    </system.web>
  </location>
  <location path="Scripts">
    <system.web>
      <authorization>
        <allow users="*"/>
      </authorization>
    </system.web>
  </location>
  <location path="Images">
    <system.web>
      <authorization>
        <allow users="*"/>
      </authorization>
    </system.web>
  </location>
  <location path="Help">
    <system.web>
      <authorization>
        <allow users="*"/>
      </authorization>
    </system.web>
  </location>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <validation validateIntegratedModeConfiguration="false"/>
    <handlers>
      <add name="Telerik_Web_UI_WebResource_axd" verb="*" preCondition="integratedMode" path="Telerik.Web.UI.WebResource.axd" type="Telerik.Web.UI.WebResource"/>
    </handlers>
  </system.webServer>

至于验证码:

// log them in and authenticate
                                FormsAuthentication.SetAuthCookie(this.txtUsername.Text, false);
                                FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, this.txtUsername.Text, DateTime.Now, DateTime.Now.AddYears(1), false, this.txtUsername.Text);

                                // For security reasons we may hash the cookies
                                string hashCookies = FormsAuthentication.Encrypt(ticket);
                                HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, hashCookies);
                                cookie.Path = FormsAuthentication.FormsCookiePath;
                                cookie.Expires = ticket.Expiration;

                                // add the cookie to user browser
                                Response.Cookies.Add(cookie);

                                    Session[CommonStrings.USER_LOGGED_IN] = userResponse.User;



                                // if DefaultWebPage is not null then redirect to that otherwise, default behavior.
                                if (!string.IsNullOrWhiteSpace(userResponse.User.DefaultWebPage))
                                {
                                    Response.Redirect(userResponse.User.DefaultWebPage, false);
                                }
                                else
                                {
                                    FormsAuthentication.RedirectFromLoginPage(this.txtUsername.Text, false);
                                }

1 个答案:

答案 0 :(得分:0)

如果我没记错的话,我过去经历过类似的事情......你可能在web.config档案中遗漏了machinekey

<machineKey 
  validationKey="EFE16B647D7AF66E1D223402ECC44428B424A442873221EC47E24358B58FEDEE7DFB97B4907605AC74670B5BC419C1C9E8980D43D84DA895275F9FB30E5078D6"
  decryptionKey="F8BB1E557DEE7AE224A08FCFB429498D218D4D65FF19CA0E160F5D68382B53C7"
  validation="SHA1" decryption="AES"

/>