无法再从 Visual Studio 为 .NET 项目运行 localhost 调试站点

Posted

技术标签:

【中文标题】无法再从 Visual Studio 为 .NET 项目运行 localhost 调试站点【英文标题】:Can no longer run localhost debug site from Visual Studio for a .NET project 【发布时间】:2018-05-28 10:05:36 【问题描述】:

我正在维护一个我没有编写的老化 C# .NET MVC 网站。一切都很好,但奇怪的事情发生了:

当尝试使用 F5 从 Visual Studio 2017 本地运行项目时,它突然加载了 Chrome 并立即重定向到该窗口中的 www.mywebsite.com 地址,而不是通常的 localhost:64874 地址。

我不知道如何阻止它重定向到实时网站。它从来没有这样做过,唯一似乎改变的是我暂时使用不同的 web.config 来连接到不同的数据库,Visual Studio 说

'该页面无法在调试模式下运行,因为在 Web.config 文件中未启用调试。你想做什么?'

我检查了“修改 Web.config 文件以启用调试”。

从那时起,Chrome 启动了 www.mywebsite.com,我所做的一切都无法让它回到运行 localhost - 如果我在调试 Chrome 窗口中输入 localhost:64874 地址,它会立即重定向到 www。

我将 web.config 编辑为 'debug="false"',这使它运行但没有调试,这有点没用。一旦我将其恢复为“真实”,我就会返回 www.mywebsite.com。

我搜索了“www.mywebsite.com”,但在整个代码库中都没有提到它。我能看到的任何地方都没有设置重定向规则。

有什么想法吗? (我确实查看了类似的问题,但没有一个完全相同或解决了问题)。

编辑了下面的 web.config:

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <configSections>
        <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
        <sectionGroup name="descriptionGroup">
          <section name="description" type="Objects.DescriptionSection" allowLocation="true" allowDefinition="Everywhere" />
        </sectionGroup>
      </configSections>
      <descriptionGroup>
        <description>
          <AboutUs description="about us" keywords="FUUUUU" />
          <ContactUs description="contact us" />
          <WWT description="wwt" />
          <WET description="wet" />
          <CookiePolicy description="cookie policy" />
          <Advertise description="advertise" />
        </description>
      </descriptionGroup>
      <connectionStrings>
        <add name="WaterPlain" connectionString="data source=tcp:123.123.123.123;initial catalog=mywebsite_partnership;user id=sa;password=passwordRemoved;MultipleActiveResultSets=True;" />
        <add name="mywebsiteDbEntities" connectionString="metadata=res://*/Models.mywebsiteDbModel.csdl|res://*/Models.mywebsiteDbModel.ssdl|res://*/Models.mywebsiteDbModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=tcp:123.123.123.123;initial catalog=mywebsite_partnership;user id=sa;password=passwordRemoved;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
        <add name="mywebsiteNews" connectionString="data source=tcp:123.123.123.123;initial catalog=mywebsite_News1;user id=sa;password=passwordRemoved;MultipleActiveResultSets=True;" />
        <add name="mywebsite_News1Entities" connectionString="metadata=res://*/Models.mywebsiteNews.csdl|res://*/Models.mywebsiteNews.ssdl|res://*/Models.mywebsiteNews.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=tcp:123.123.123.123;initial catalog=mywebsite_News1;user id=sa;password=passwordRemoved;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
        <add name="ProductPlain" connectionString="data source=tcp:123.123.123.123;initial catalog=mywebsite_PF_TEST;user id=sa;password=passwordRemoved;MultipleActiveResultSets=True;" />
        <add name="mywebsite_PF_TESTEntities" connectionString="metadata=res://*/Models.Products.csdl|res://*/Models.Products.ssdl|res://*/Models.Products.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=tcp:123.123.123.123;initial catalog=mywebsite_PF_TEST;user id=sa;password=passwordRemoved;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
        <add name="CustomMembershipPlain" connectionString="data source=tcp:123.123.123.123;initial catalog=RegisteredUsers;user id=sa;password=passwordRemoved;MultipleActiveResultSets=True;" />
        <add name="RegisteredUsersEntities" connectionString="metadata=res://*/Models.CustomMembership.csdl|res://*/Models.CustomMembership.ssdl|res://*/Models.CustomMembership.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=tcp:123.123.123.123;initial catalog=RegisteredUsers;persist security info=True;user id=sa;password=passwordRemoved;application name=EntityFramework;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />
        <add name="mywebsite_WWEMPPlain" connectionString="data source=tcp:123.123.123.123;initial catalog=mywebsite_WWEMP;persist security info=True;user id=sa;password=passwordRemoved;MultipleActiveResultSets=True;" />
        <add name="mywebsite_WWEMPEntities" connectionString="metadata=res://*/Models.Suppliers.csdl|res://*/Models.Suppliers.ssdl|res://*/Models.Suppliers.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=tcp:123.123.123.123;initial catalog=mywebsite_WWEMP;persist security info=True;user id=sa;password=passwordRemoved;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
        <add name="mywebsite_blogPlain" connectionString="data source=tcp:123.123.123.123;initial catalog=mywebsite_blog;persist security info=True;user id=sa;password=passwordRemoved;MultipleActiveResultSets=True;" />
        <add name="mywebsite_blogEntities" connectionString="metadata=res://*/Models.Blogs.csdl|res://*/Models.Blogs.ssdl|res://*/Models.Blogs.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=tcp:123.123.123.123;initial catalog=mywebsite_blog;user id=sa;password=passwordRemoved;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
      </connectionStrings>
      <appSettings>
        <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="ServerPrefix" value="https://s3BucketRemoved.s3.amazonaws.com" />
        <add key="SupplierServerPrefix" value="http://removed.cloudimg.io/s/width/226/http://s3BucketRemoved.s3.amazonaws.com" />
        <add key="SupplierServerPressReleasePrefix" value="http://removed.cloudimg.io/s/crop/700x100/http://s3BucketRemoved.s3.amazonaws.com" />
        <add key="BlogAuthorPrefix" value="http://s3BucketRemoved.s3.amazonaws.com" />
        <add key="BlogHomeUrlPrefix" value="https://removed.cloudimg.io/s/crop/300x200/https://s3BucketRemoved.s3.amazonaws.com" />
        <add key="RegisterUrl" value="https://subs.mywebsite.co.uk/register?" />
        <add key="RetrievePwdUrl" value="https://subs.mywebsite.co.uk/forgottenpassword?" />
        <add key="MainUrl" value="http://localhost:64874" />
        <add key="ReturnUrl" value="http://localhost:64874/" />
        <add key="UpdateUserInfoUrl" value="https://subs.mywebsite.co.uk/edituserdetails?partyid=" />
        <add key="AccessHash" value="removed" />
        <add key="AccessToken" value="removed" />
        <add key="APIUrl" value="https://www.anapisite.com/" />
        <add key="LoadCount" value="15" />
        <add key="TwitterConsumerKey" value="removed" />
        <add key="TwitterConsumerSecret" value="removed" />
        <add key="TwitterToken" value="removed-removed" />
        <add key="TwitterTokenSecret" value="removed" />
        <add key="TwitterIDS" value="removed" />
        <add key="enableSimpleMembership" value="false" />
        <add key="autoFormsAuthentication" value="false" />
        <add key="DES_KEY" value="mywebsite" />
        <add key="roundtableFolder" value="C:\inetpub\folder\Content\folder\" />
        <add key="LuceneIndexFolder" value="c:\ProgramData\folder\" />
        <add key="staticImagesPath" value="../images" />
        <add key="TitleLength" value="100" />
        <add key="IntroLength" value="100" />
        <add key="DigitalIssuesWWTMagazine" value="c:\inetpub\wwwroot\folder\afile.xml" />
        <add key="DigitalIssuesWETNews" value="c:\inetpub\wwwroot\folder\afile.xml" />
        <add key="RegistrationGoal" value="http://localhost:64874/Register?Url=" />
        <!-- Banners Configuration-->
        <add key="LeaderBanner" value="1011" />
        <add key="MPUBanner" value="1012" />
      </appSettings>
      <system.web>

        <caching>
          <outputCacheSettings>
            <outputCacheProfiles>
              <add name="Cache" duration="0" varyByParam="none" />
            </outputCacheProfiles>
          </outputCacheSettings>
        </caching>
        <customErrors mode="Off" defaultRedirect="/Error">
          <error redirect="/Error/NotFound" statusCode="404" />
          <error redirect="/Error/InternalServerError" statusCode="500" />
        </customErrors>
        <compilation debug="true" targetFramework="4.0">
          <assemblies>
            <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
          </assemblies>
        </compilation>
        <authentication mode="Forms">
          <forms loginUrl="~/Account/SignIn" timeout="2880" />
        </authentication>
        <httpRuntime requestValidationMode="2.0" />
        <pages validateRequest="false" />
        <membership defaultProvider="CustomMembershipProvider">
          <providers>
            <clear />
            <add name="CustomMembershipProvider" type="mywebsite.CustomMembershipProvider" connectionStringName="CustomMembershipPlain" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="true" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
          </providers>
        </membership>
      </system.web>
      <system.webServer>
        <validation validateIntegratedModeConfiguration="false" />
        <!--optimization- starts-->
        <modules runAllManagedModulesForAllRequests="true">
          <add name="HttpHeadersCleanup " type="mywebsite.HttpHeadersCleanup, mywebsite" />
        </modules>
        <!--optimization- ends-->
        <handlers>
          <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
          <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
          <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
          <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
          <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
          <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
        </handlers>
        <!--optimization- starts-->
        <httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
          <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" />
          <dynamicTypes>
            <add mimeType="text/*" enabled="true" />
            <add mimeType="message/*" enabled="true" />
            <add mimeType="image/*" enabled="true" />
            <add mimeType="application/x-pointplus" enabled="true" />
            <add mimeType="text/css" enabled="true" />
            <add mimeType="application/x-javascript" enabled="true" />
            <add mimeType="application/javascript" enabled="true" />
            <add mimeType="text/javascript" enabled="true" />
            <add mimeType="*/*" enabled="false" />
          </dynamicTypes>
          <staticTypes>
            <add mimeType="text/*" enabled="true" />
            <add mimeType="message/*" enabled="true" />
            <add mimeType="image/*" enabled="true" />
            <add mimeType="application/x-pointplus" enabled="true" />
            <add mimeType="text/css" enabled="true" />
            <add mimeType="application/x-javascript" enabled="true" />
            <add mimeType="application/javascript" enabled="true" />
            <add mimeType="text/javascript" enabled="true" />
            <add mimeType="*/*" enabled="false" />
          </staticTypes>
        </httpCompression>
        <urlCompression doStaticCompression="true" doDynamicCompression="true" dynamicCompressionBeforeCache="true" />
        <staticContent>
          <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="30.00:00:00" cacheControlCustom="Public" />
        </staticContent>
        <httpProtocol>
          <customHeaders>
            <remove name="X-AspNet-Version" />
            <remove name="X-AspNetMvc-Version" />
            <remove name="Server" />
            <remove name="X-Powered-By" />
            <remove name="ETag" />
            <!--<clear/><add name="ETag" value=""/>-->
          </customHeaders>
        </httpProtocol>
        <!--optimization- ends-->
      </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="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
          </dependentAssembly>
          <!--<dependentAssembly>
            <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-2.2.13.0" newVersion="2.2.13.0" />
          </dependentAssembly>-->
          <dependentAssembly>
            <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System" publicKeyToken="b77a5c561934e089" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Web.Razor" publicKeyToken="31bf3856ad364e35" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Web.WebPages.Razor" publicKeyToken="31bf3856ad364e35" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-2.2.13.0" newVersion="2.2.13.0" />
          </dependentAssembly>
        </assemblyBinding>
      </runtime>
      <entityFramework>
        <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
          <parameters>
            <parameter value="v11.0" />
          </parameters>
        </defaultConnectionFactory>
      </entityFramework>
      <system.net>
        <mailSettings>
          <!--<smtp from="mywebsite@mywebsite.net" deliveryMethod="Network">
            <network host="smtp.sendgrid.net" password="0hPl3as3N0tAga1n" userName="mywebsitedotnet" port="587" />
          </smtp>-->
          <smtp from="email@mywebsite.com" deliveryMethod="Network">
            <network host="smtp.sendgrid.net" password="passwordRemoved" userName="mywebsite" port="587" />
          </smtp>
        </mailSettings>
      </system.net>
    </configuration>

【问题讨论】:

Chrome 缓存重定向很长时间。也许重定向曾经在那里。 ***.com/questions/16154672/… 您是否将解决方案配置设置为“调试”或“发布”?你能告诉我们 web.config 和 web.debug.config 吗? (注意不要发布任何敏感数据,如连接字符串或密码)您是否尝试使用不同的浏览器,例如 IE? 我使用 Chrome 开发工具/应用程序/清除站点数据清除了缓存。没有快乐。 目前设置为“调试”。我会看看我是否可以准备一个 web.config 文件在这里发布 已编辑以添加经过编辑的 web.config,谢谢! 【参考方案1】:

看起来像 chrome 兑现重定向。 你应该清除cashe,你可以试试cashe killer 自动完成

或者您可以手动操作Bast answer for this question

【讨论】:

我已经尝试了这些页面上的所有解决方案,回复:缓存。尝试清空缓存和硬重新加载,然后,我清除了所有内容的整个缓存,包括我的整个历史记录和密码,但问题仍然存在! 我将答案授予您@garret,因为解决方案最终隐藏在该页面上的一个建议中:在 chrome://net-internals 和最右边打开 drop -向下并选择“清除缓存”。但具体来说,您必须在编译 .NET 项目后运行重定向页面时执行此操作,然后键入 localhost:9999 地址。然后打开此选项卡并清除缓存 - 我之前通常从 Chrome 尝试过,但它什么也没做!

以上是关于无法再从 Visual Studio 为 .NET 项目运行 localhost 调试站点的主要内容,如果未能解决你的问题,请参考以下文章

Visual Studio 2012 Vb.net 无法将配置切换到发布模式

Visual Studio 无法在 IIS 中创建网站

无法在 Visual Studio 中发布 ASP.Net 应用程序

我无法在 Visual Studio 2019 中定位 .Net Framework

VISUAL STUDIO .NET MVC 无法搭建剃刀视图

Visual Studio Xamarin Android System.Net.WebException:错误:ConnectFailure(网络无法访问)