2017-07-12 111 views
0

虽然在本地计算机上工作良好,但我的MVC应用程序似乎在生产环境中显得有点怪异。这里是我的情况:使用正确凭证登录后返回到登录操作

  1. 用户进入我的网站
  2. 用户没有登录,因此重定向到登录页面
  3. 用户输入凭据
  4. 用户被重定向到其一页一页,展示了他们信息

这一切工作正常,如果本地调试,但这里是在生产环境中的情况:

  1. 用户进入我的网站
  2. 用户没有登录,因此重定向到登录页面
  3. 用户输入凭据
  4. 应用程序试图用户重定向到页,但返回与状态的响应:

302发现

  • 用户被重定向到登录页面
  • 调试本申请局部,登录动作的响应,如果成功,不是“302找到”但

    200获取

    我通过文件系统发布网站,并期望行为酷似本地调试。

    可能的原因是什么,为什么会发生这种行为?

    • 网址登录:mydomain.com我的网页
    • 网址:mydomain.com/mypage

    的Web.config

    <?xml version="1.0" encoding="utf-8"?> 
    <!-- 
        For more information on how to configure your ASP.NET application, please visit 
        http://go.microsoft.com/fwlink/?LinkId=301880 
        --> 
    <configuration> 
        <configSections> 
        <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> 
        <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --> 
        </configSections> 
        <connectionStrings> 
        <add name="SomeConnection" connectionString="SomeConnectionString" /> 
        <add name="SomeConnection2" connectionString="SomeConnectionString2" /> 
        </connectionStrings> 
        <appSettings> 
        <add key="webpages:Version" value="3.0.0.0" /> 
        <add key="webpages:Enabled" value="false" /> 
        <add key="ClientValidationEnabled" value="true" /> 
        <add key="UnobtrusiveJavaScriptEnabled" value="true" /> 
        <add key="vs:EnableBrowserLink" value="true" /> 
        </appSettings> 
        <!-- 
        For a description of web.config changes see http://go.microsoft.com/fwlink/?LinkId=235367. 
    
        The following attributes can be set on the <httpRuntime> tag. 
         <system.Web> 
         <httpRuntime targetFramework="4.6" /> 
         </system.Web> 
        --> 
        <system.web> 
        <authentication mode="None" /> 
        <compilation debug="true" targetFramework="4.6.1"> 
         <assemblies> 
         <add assembly="System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" /> 
         <add assembly="System.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" /> 
         <add assembly="System.Data.Entity.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> 
         </assemblies> 
         <buildProviders> 
         <add extension=".edmx" type="System.Data.Entity.Design.AspNet.EntityDesignerBuildProvider" /> 
         </buildProviders> 
        </compilation> 
        <httpRuntime targetFramework="4.5" maxRequestLength="1048576" relaxedUrlToFileSystemMapping="true" /> 
        <customErrors mode="Off" /> 
        <httpModules> 
         <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" /> 
        </httpModules> 
        </system.web> 
        <system.webServer> 
        <staticContent> 
         <remove fileExtension=".json" /> 
         <mimeMap fileExtension=".json" mimeType="application/json; charset=UTF-8" /> 
         <remove fileExtension=".woff" /> 
         <mimeMap fileExtension=".woff" mimeType="application/font-woff" /> 
         <remove fileExtension=".woff2" /> 
         <mimeMap fileExtension=".woff2" mimeType="application/font-woff2" /> 
        </staticContent> 
        <modules> 
         <remove name="FormsAuthentication" /> 
         <remove name="ApplicationInsightsWebTracking" /> 
         <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler" /> 
        </modules> 
        <handlers> 
         <remove name="ExtensionlessUrlHandler-Integrated-4.0" /> 
         <remove name="OPTIONSVerbHandler" /> 
         <remove name="TRACEVerbHandler" /> 
         <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" /> 
        </handlers> 
        <validation validateIntegratedModeConfiguration="false" /> 
        </system.webServer> 
        <runtime> 
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
         <dependentAssembly> 
         <assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" /> 
         <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" /> 
         </dependentAssembly> 
         <dependentAssembly> 
         <assemblyIdentity name="Microsoft.Owin.Security.OAuth" publicKeyToken="31bf3856ad364e35" /> 
         <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" /> 
         </dependentAssembly> 
         <dependentAssembly> 
         <assemblyIdentity name="Microsoft.Owin.Security.Cookies" publicKeyToken="31bf3856ad364e35" /> 
         <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" /> 
         </dependentAssembly> 
         <dependentAssembly> 
         <assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" /> 
         <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" /> 
         </dependentAssembly> 
         <dependentAssembly> 
         <assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" /> 
         <bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" /> 
         </dependentAssembly> 
         <dependentAssembly> 
         <assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" /> 
         <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" /> 
         </dependentAssembly> 
         <dependentAssembly> 
         <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" /> 
         <bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930" /> 
         </dependentAssembly> 
         <dependentAssembly> 
         <assemblyIdentity name="Microsoft.Data.Edm" publicKeyToken="31bf3856ad364e35" culture="neutral" /> 
         <bindingRedirect oldVersion="0.0.0.0-5.6.4.0" newVersion="5.6.4.0" /> 
         </dependentAssembly> 
         <dependentAssembly> 
         <assemblyIdentity name="Microsoft.Data.Services.Client" publicKeyToken="31bf3856ad364e35" culture="neutral" /> 
         <bindingRedirect oldVersion="0.0.0.0-5.6.4.0" newVersion="5.6.4.0" /> 
         </dependentAssembly> 
         <dependentAssembly> 
         <assemblyIdentity name="Microsoft.Data.OData" publicKeyToken="31bf3856ad364e35" culture="neutral" /> 
         <bindingRedirect oldVersion="0.0.0.0-5.6.4.0" newVersion="5.6.4.0" /> 
         </dependentAssembly> 
         <dependentAssembly> 
         <assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" /> 
         <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" /> 
         </dependentAssembly> 
         <dependentAssembly> 
         <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" /> 
         <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" /> 
         </dependentAssembly> 
         <dependentAssembly> 
         <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" /> 
         <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" /> 
         </dependentAssembly> 
         <dependentAssembly> 
         <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" /> 
         <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" /> 
         </dependentAssembly> 
         <dependentAssembly> 
         <assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" culture="neutral" /> 
         <bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" /> 
         </dependentAssembly> 
         <dependentAssembly> 
         <assemblyIdentity name="Microsoft.ApplicationInsights" publicKeyToken="31bf3856ad364e35" culture="neutral" /> 
         <bindingRedirect oldVersion="0.0.0.0-2.1.0.0" newVersion="2.1.0.0" /> 
         </dependentAssembly> 
         <dependentAssembly> 
         <assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" /> 
         <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" /> 
         </dependentAssembly> 
         <dependentAssembly> 
         <assemblyIdentity name="Microsoft.WindowsAzure.Storage" publicKeyToken="31bf3856ad364e35" culture="neutral" /> 
         <bindingRedirect oldVersion="0.0.0.0-4.3.0.0" newVersion="4.3.0.0" /> 
         </dependentAssembly> 
         <dependentAssembly> 
         <assemblyIdentity name="Microsoft.AI.Agent.Intercept" publicKeyToken="31bf3856ad364e35" culture="neutral" /> 
         <bindingRedirect oldVersion="0.0.0.0-2.0.1.0" newVersion="2.0.1.0" /> 
         </dependentAssembly> 
        </assemblyBinding> 
        </runtime> 
        <entityFramework codeConfigurationType="SomeProject.Infrastructure.SqlAzureConfiguration, SomeProject.Infrastructure"> 
        <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework"> 
         <parameters> 
         <parameter value="mssqllocaldb" /> 
         </parameters> 
        </defaultConnectionFactory> 
        <providers> 
         <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /> 
        </providers> 
        </entityFramework> 
        <system.diagnostics> 
        <trace autoflush="true" indentsize="0"> 
         <listeners> 
         <add name="myAppInsightsListener" type="Microsoft.ApplicationInsights.TraceListener.ApplicationInsightsTraceListener, Microsoft.ApplicationInsights.TraceListener" /> 
         </listeners> 
        </trace> 
        </system.diagnostics> 
    </configuration> 
    
    +1

    您的应用在http或https或两者上运行吗?什么是登录页面的URL?什么是MyPage的URL? – mjwills

    +0

    请包括您的web.config的内容(在删除密码等)后。 – mjwills

    +0

    看看:https://stackoverflow.com/questions/3413402/website-returns-302-instead-of-200 – Kirhgoph

    回答

    0

    发现我的问题

    这是非常规格与我的情况不同,但显然我的_LoginPartial.cshtml未发布到远程站点。这导致网站无法呈现,返回主页,我放置了我的登录页面,因此没有单独的登录页面,因为此网站不应该由没有登录的人输入。

    发布_LoginPartial.cshtml之后,所有内容都能够渲染,并且我的网站现在可以按预期再次运行。