简体   繁体   English

如何在本地IIS 7中运行asp.net项目

[英]How can I run asp.net project Locally IIS 7

I have a asp.net project that i deploy onto an environment using TFS-2017 Release Managment We have problems that when we deploy the website users have old (cached) images/content I want to configure IIS 7 so that i can Test few solutions locally, the website opens on localhost:89 but when i click a button it re-directs me to a live website, I tried configuring the Hosts file with 我有一个使用TFS-2017版本管理部署到环境中的asp.net项目我们遇到的问题是,当部署网站时,用户具有旧的(缓存的)图像/内容,我想配置IIS 7,以便我可以测试一些解决方案在本地,该网站在localhost:89上打开,但是当我单击按钮将其重定向到实时网站时,我尝试使用以下命令配置Hosts文件

127.0.0.1 example.com
127.0.0.1 www.example.com

But this does not work, my web.config file has a lot of appSettings that contain urls that's what causing me to redirect (I Think). 但这是行不通的,我的web.config文件中有很多appSettings,它们包含导致我进行重定向的URL(我认为)。

QUESTION: How can I configure IIS so it only uses the Localhost:89 and when I click a button it will redirect me instead of www.example.com to 127.0.0.1:89? 问题:如何配置IIS,使其仅使用Localhost:89,并且单击按钮时它将重定向我,而不是将www.example.com重定向到127.0.0.1:89?

How can I configure IIS so it only uses the Localhost:89 and when I click a button it will redirect me instead of www.example.com to 127.0.0.1:89? 如何配置IIS,使其仅使用Localhost:89,当我单击按钮时,它将把我而不是www.example.com重定向到127.0.0.1:89?

You cannot configure IIS for this 您不能为此配置IIS

IIS does not redirect on it's own it is the application which is doing it.If your application has code written to redirect to another page,from IIS side you cannot do anything.The flow will be like this IIS本身并不能自行重定向。如果您的应用程序编写了用于重定向到另一个页面的代码,则从IIS方面您将无能为力。流程将像这样

  1. User Clicks on a button 用户单击按钮
  2. On the asp.net side,application code does some processing(may be checks the incoming URL and if it does not match something) and redirct to www.example.com.This sends a response 302 status(or any 301 or 307) with Location header pointing to www.example.com 在asp.net端,应用程序代码会进行一些处理(可能会检查传入的URL,如果它与某些内容不匹配),然后重定向到www.example.com。这会发送响应302状态(或任何301或307),并带有指向www.example.com的位置标题
  3. Your browser sees the 302 status and redirects the user to www.example.com 您的浏览器会看到302状态,并将用户重定向到www.example.com

Since redirection is a response message send by application and the actual redirection is done by the browser ,from IIs side you cannot do much. 由于重定向是应用程序发送的响应消息,而实际的重定向是由浏览器完成的,因此从II方面讲,您不能做太多事情。

As you were doing you can tell the browser that www.example.com is localhost(by editing hosts(C:\\Windows\\System32\\drivers\\etc\\hosts) file.But that has nothing to do with IIS. 在执行操作时,可以通过编辑hosts(C:\\ Windows \\ System32 \\ drivers \\ etc \\ hosts)文件来告诉浏览器www.example.com是localhost,但这与IIS没有关系。

You have to check with application developers to see why it is redirecting and have conditional redirects based on settings. 您必须与应用程序开发人员联系,以查看为什么要重定向并根据设置进行条件重定向。

The Hosts file configuration looks fine Hosts文件配置看起来不错

127.0.0.1 example.com
127.0.0.1 www.example.com

But you may already know what it only works in the same machine.So if you ping www.example com from command line,you should get the output as follows 但是您可能已经知道它只能在同一台机器上工作。因此,如果从命令行ping www.example com,则应获得如下输出

D:\>ping www.example.com

Pinging www.example.com [127.0.0.1] with 32 bytes of data:
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128

Ping statistics for 127.0.0.1:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 0ms, Average = 0ms

One your ping works fine,you have to close the browser completely and reopen it(if chrome,close all instances of chrome).Then access www.example.com from your browser and it should go to localhost. 一次ping正常,您必须完全关闭浏览器并重新打开它(如果使用chrome,请关闭所有chrome实例)。然后从浏览器访问www.example.com,它应转到localhost。

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

相关问题 在IIS 7.5上本地运行(部署?)ASP.NET MVC - Run (deploy?) ASP.NET MVC on IIS 7.5 locally 启动应用程序时发生错误,一旦我在 IIS 上运行我的 ASP.NET 核心项目 - An error occurred while starting the application, once I run my ASP.NET Core project on IIS 部署 ASP.NET Core Docker 项目 - 收到 405 错误(在我的 IIS 本地,Web 请求有效)。 如何解决? - Deploy ASP.NET Core Docker project - get a 405 error (locally in my IIS, web requests works). How to fix it? 如何在没有 IDE 的情况下运行 asp.net web 应用程序项目 - How can I run asp.net web app project without IDE 如何从托管在 iis 上的 Asp.net 项目运行 Exe 文件 - How To Run Exe File From Asp.net project which is host on iis ASP.NET 项目在 VS 运行时在本地运行,但不在本地计算机或服务器上的 IIS 上运行 - ASP.NET project works locally on build when VS is running but not on IIS on my local machine or my server 如何在本地运行ASP.NET C#Web应用程序? - How to run ASP.NET C# web application locally? 无法使用本地IIS服务器运行asp.net应用程序 - Can not run asp.net application using Local IIS Server ASP.NET剃须刀是否在本地运行? - Is ASP.NET razor run locally? 我如何在ASP.NET网站项目中使用XAML - How can i use xaml in asp.net website project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM