ASP MVC 4用户在每次请求后注销

时间:2014-10-04 06:30:11

标签: asp.net-mvc logout authorize-attribute asp.net-authorization role-base-authorization

我正在研究在我的开发系统上工作得非常好的Asp Mvc 4项目,它在我的演示托管服务器上也非常好用。 但是当我在客户端的服务器上传网站时,它要求在每个页面上登录。当我登录一个页面时,我可以在该页面上执行操作。但如果它打开另一个页面,它会重定向我再次登录页面。

我无法理解原因。因为它在我的本地系统和我的演示托管上工作正常。但在客户端托管它的行为就像这样。

我正在使用自定义授权属性。但我在另一个运行良好的网站上使用此方法。

请提出任何想法或解决方案。

以下是我的web.config文件:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <section name="AccountingSystem.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
      <section name="UI.Web.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    </sectionGroup>
  </configSections>
  <connectionStrings>
    <add name="DefaultConnection" connectionString="Data Source=SQLSERVER4;Initial Catalog=clouddms_dms_demo;Integrated Security=False;User ID=*****;Password=******;Connect Timeout=15;Encrypt=False;Packet Size=4096" providerName="System.Data.SqlClient" />
    <add name="DocumentManagerEntities" connectionString="metadata=res://*/DataContext.csdl|res://*/DataContext.ssdl|res://*/DataContext.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=SQLSERVER4;initial catalog=clouddms_dms_demo;integrated security=False;;User ID=******;Password=*****;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
    <add key="webpages:Version" value="2.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="PreserveLoginUrl" value="true" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
    <add key="microsoft.visualstudio.teamsystems.backupinfo" value="1;web.config.backup" />
    <add key="microsoft.visualstudio.teamsystems.aspnetdevserver:/" value="8804;True;7480;1;-8587902403488351008" />
  </appSettings>
  <system.web>
    <compilation targetFramework="4.0" />
    <customErrors mode="Off" defaultRedirect="~/Error/" />
    <!--<customErrors mode="On" defaultRedirect="~/Error/">
      <error statusCode="403" redirect="~/Error/InsufcientPrivilage"/>
      <error statusCode="404" redirect="~/Error/PageNotFound"/>
    </customErrors>-->
    <authentication mode="Forms">
      <forms loginUrl="~/Account/Login" timeout="2880" />
    </authentication>
    <pages>
      <namespaces>
        <add namespace="System.Web.Helpers" />
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Optimization" />
        <add namespace="System.Web.Routing" />
        <add namespace="System.Web.WebPages" />
      </namespaces>
    </pages>
    <profile inherits="UI.Web.UserProfile" defaultProvider="DefaultProfileProvider">
      <providers>
        <add name="DefaultProfileProvider" type="System.Web.Providers.DefaultProfileProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" />
      </providers>
    </profile>
    <!--<profile defaultProvider="DefaultProfileProvider">
      <providers>
        <add name="DefaultProfileProvider" type="System.Web.Providers.DefaultProfileProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/"/>
      </providers>
    </profile>-->
    <membership defaultProvider="DefaultMembershipProvider">
      <providers>
        <add name="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="true" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
      </providers>
    </membership>
    <roleManager enabled="true" defaultProvider="DefaultRoleProvider">
      <providers>
        <add connectionStringName="DefaultConnection" applicationName="/" name="DefaultRoleProvider" type="System.Web.Providers.DefaultRoleProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
      </providers>
    </roleManager>
    <sessionState mode="InProc" customProvider="DefaultSessionProvider">
      <providers>
        <add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" />
      </providers>
    </sessionState>
      </system.web>
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <modules runAllManagedModulesForAllRequests="true" />
        <directoryBrowse enabled="false" />
        <defaultDocument>
            <files>
                <clear />
                <add value="Default.htm" />
                <add value="Default.asp" />
                <add value="index.htm" />
                <add value="index.html" />
                <add value="iisstart.htm" />
                <add value="default.aspx" />
                <add value="index.php" />
            </files>
        </defaultDocument>
      </system.webServer>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
                <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <entityFramework>
        <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
      </entityFramework>
  <applicationSettings>
    <UI.Web.Properties.Settings>
      <setting name="DataRootDir" serializeAs="String">
        <value>/Data/</value>
      </setting>
      <setting name="DataUserRoot" serializeAs="String">
        <value>/Data/Users/</value>
      </setting>
      <setting name="SiteDatalDir" serializeAs="String">
        <value>/Data/SiteData/</value>
      </setting>
      <setting name="FileIconDir" serializeAs="String">
        <value>/Data/SiteData/Icons/</value>
      </setting>
      <setting name="ContactPicDir" serializeAs="String">
        <value>/Data/SiteData/ContactPic/</value>
      </setting>
    </UI.Web.Properties.Settings>
    <!--<UI.Web.Properties.Settings>
  <setting name="DataGlobalDir" serializeAs="String">
            <value>/Data/</value>
      </setting>
      <setting name="UserDataRootDir" serializeAs="String">
        <value>/Data/Company/</value>
          </setting>
      <setting name="SiteDatalDir" serializeAs="String">
        <value>/Data/Site/</value>
      </setting>
    </UI.Web.Properties.Settings>-->
      </applicationSettings>
</configuration>

2 个答案:

答案 0 :(得分:0)

我认为您在Web.config中缺少计算机密钥,生成一个here并将其放在Web.config文件中。

<system.web>
    place your generated machine key here
</system.web>

机器密钥用于:配置用于加密,解密和验证表单身份验证数据和视图状态数据的算法和密钥,以及用于进程外会话状态识别的算法和密钥。

答案 1 :(得分:0)

我尝试了很多方法,也在互联网上搜索但找不到解决方案。主要的困惑是同样的构建在其他服务器上运行。但在实际的客户端服务器上我签了用户。 所以我要求我的客户更改托管服务器。这是有效的。

现在新托管它的工作很棒.............. 感谢@Eric Wang的想法。