简体   繁体   English

IIS本地主机正在重定向到实时服务器,而不是显示本地aspx文件

[英]IIS localhost is redirecting to the live server instead of showing local aspx files

I need to redesign a site front-end to make it responsive, the site is based on C# and ASPX. 我需要重新设计网站前端以使其响应,该网站基于C#和ASPX。 I am familiar with working PHP local development environment by using WAMP so for this case I installed visualstudio web express because of its IIS server features for testing local development. 我对使用WAMP的PHP本地开发环境很熟悉,因此在这种情况下,我安装了visualstudio web express,因为它具有用于测试本地开发的IIS服务器功能。

The client sent the folder from its ftp for me to work on so I have everything ready but the problem which I am facing is that when I try to right-click on the website folder from the solution explorer to view in the browser the localhost is redirecting to the actual live site which is running on the server instead of taking me to the localhost with local files so that I can have a view of my modification and changes. 客户端从ftp发送了该文件夹供我处理,所以我已经准备好一切,但是面临的问题是,当我尝试从解决方案资源管理器右键单击网站文件夹以在浏览器中查看时,本地主机是重定向到服务器上正在运行的实际活动站点,而不是将我带到本地文件的本地主机,以便可以查看我的修改和更改。

I am unable to figuring out the problem may be there is something I need to change or replace in the webconfig file. 我无法弄清楚问题,可能是我需要在webconfig文件中更改或替换某些内容。 I am working in asp environment for the first time your help and guidance in this regard will be very appreciated. 我是第一次在ASP环境中工作,在此方面的帮助和指导将非常感谢。

Many thanks. 非常感谢。

I had this same problem just now as well as two or three times before and haven't pinned down a clear cut resolution, though I've tried removing redirects, checking the Global.asax, commenting out default document files in the Web.config, etc. I'm mainly working in Chrome on Windows 7, and after I cleared Chrome's cache localhost started working for me again. 我现在以及之前两次或三次都遇到过同样的问题,尽管我尝试删除重定向,检查Global.asax,注释掉Web.config中的默认文档文件,但都没有明确的解决方案等等。我主要在Windows 7上的Chrome中工作,并且清除了Chrome的缓存后,localhost再次为我工作。 I don't know if the answer is as simple as that or if the solution comes from some combination of things. 我不知道答案是否就这么简单,或者解决方案是否来自某种组合。 All I know is nothing else seemed to work, then clearing the browser cache did. 我所知道的似乎没有其他办法,然后清除浏览器缓存。

PROBLEM 问题

I was facing this problem because I wrote this rule inside webconfig file. 遇到此问题是因为我在webconfig文件中编写了此规则。

 <rules>
  <rule name="CanonicalHostNameRule1">
    <match url="(.*)" />
    <conditions>
      <add input="{HTTP_HOST}" pattern="^www.abc\.com$" negate="true" />
    </conditions>
    <action type="Redirect" url="www.abc.com/{R:1}" />
  </rule>
</rules>

And because of this when I debug the solution the localhost is replaced with www.abc.com 因此,当我调试解决方案时,将本地主机替换为www.abc.com

SOLUTION

Just remove this rule if written 只需删除此规则(如果已写)

WHY USE RULE 为什么使用规则

These rules are used when you want to customize the url ,you can read further about Url Rewrite here 当您要自定义url时使用这些规则,您可以在此处进一步了解Url Rewrite

Redirecting to the live site from visual studio or localhost can be caused by a faulty url rewrite rule in the site web config. 从Visual Studio或本地主机重定向到实时站点可能是由于站点Web配置中的URL重写规则错误所致。 Even if the rule is deleted, the browser may cache the rule if it is a permanent redirect, and therefore clearing the browser cache and fixing the faulty rule can be a viable solution. 即使删除了规则,如果浏览器是永久重定向,浏览器也可以缓存该规则,因此清除浏览器缓存并修复错误的规则可能是可行的解决方案。

See article https://theludditedeveloper.wordpress.com/2016/01/06/iis-url-rewrite-gotcha-2/ 参见文章https://theludditedeveloper.wordpress.com/2016/01/06/iis-url-rewrite-gotcha-2/

For me it was because the web.config had a rewrite rule added in it for SSL purpose. 对我而言,这是因为web.config中添加了重写规则以用于SSL。 However, once I removed it, it still kept me redirecting to the live site. 但是,一旦删除它,它仍然使我重定向到实时站点。 I wasted couple of hours searching the code without anything making sense. 我浪费了几个小时搜索代码,而没有任何意义。 And then it turned out that the cache was the issue as the browser was still doing the redirection. 然后事实证明,缓存是问题所在,因为浏览器仍在进行重定向。 So, I cleared the cache and it was solved. 因此,我清除了缓存并解决了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM