简体   繁体   English

IIS和IIS Express在本地为MVC4 Azure应用程序抛出403错误

[英]IIS & IIS Express throwing 403 errors locally for MVC4 Azure app

I have a C# MVC4 application that I recently migrated to an Azure web role. 我有一个C#MVC4应用程序,我最近迁移到Azure Web角色。 I can publish/run the site just fine on the Azure platform, but when I try to run it locally using the Azure development fabric, IIS and IIS Express throw a generic 403 errors. 我可以在Azure平台上发布/运行该网站,但是当我尝试使用Azure开发结构在本地运行它时,IIS和IIS Express会抛出一般403错误。

I tried adding the following to my web.config as I've seen it mentioned in numerous posts but it didn't help. 我尝试将以下内容添加到我的web.config中,因为我已经在很多帖子中看到它,但它没有帮助。 This solution seems like a bit of a sledgehammer approach anyways since it's running ALL requests through the managed pipeline, but still, figured I'd give it a shot. 这个解决方案似乎有点像一个大锤的方法,因为它通过托管管道运行所有请求,但仍然,我想给它一个机会。

  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"></modules>
    <handlers>
      <remove name="UrlRoutingHandler"/>
    </handlers>
  </system.webServer>

I've verified that I can access the "robots.txt" file in my application root so the server is fired up and pointing to the right place, but it won't serve any of my MVC pages. 我已经验证我可以访问我的应用程序根目录中的“robots.txt”文件,因此服务器已启动并指向正确的位置,但它不会为我的任何MVC页面提供服务。

I also tried the solution in this SO answer . 我也在这个SO答案中尝试了解决方案。 No dice there either. 也没有骰子。

I've also tried switching my Azure web role to run in IIS instead of IIS Express. 我也尝试将我的Azure Web角色切换为在IIS而不是IIS Express中运行。 I get the same 403 error there. 我在那里得到了同样的403错误。 Just to be thorough, I did run aspnet_regiis -ir even though other MVC apps running locally (non-Azure) on my machine work just fine. 为了彻底,我确实运行了aspnet_regiis -ir,即使在我的机器上运行本地(非Azure)的其他MVC应用程序工作正常。

EDIT So this is interesting...when I hit F5 (my Azure project is my startup project), the Azure Compute/Storage emulators fire up and then my browser opens to http://127.0.0.1:81/ . 编辑所以这很有趣......当我点击F5(我的Azure项目是我的启动项目)时,Azure计算/存储模拟器启动,然后我的浏览器打开到http://127.0.0.1:81/ This is the URL I get the 403 error at. 这是我收到403错误的URL。

However, if I'm using IIS (not Express) and I go to the web site in IIS that Azure created during deployment, right click, "Manage Web Site" and then choose "Browse", it opens the site up at http://localhost:82/ . 但是,如果我正在使用IIS(而不是Express)并且我访问Azure在部署期间创建的IIS中的网站,请右键单击“管理网站”,然后选择“浏览”,它将在http://localhost:82/ Note "localhost" instead of 127.0.0.1 and a port of 82 instead of 81 and IT WORKS! 注意“localhost”而不是127.0.0.1和82的端口而不是81和IT工作! I can browse through my site with no problems, hit breakpoints, etc. Now if I try http://127.0.0.1:82 (using the IP, but port 82) I still get the 403. 我可以毫无问题地浏览我的网站,点击断点等。现在,如果我尝试http://127.0.0.1:82 (使用IP,但是端口82),我仍然可以获得403。

Any ideas? 有任何想法吗?

I couldn't get exact question you are asking, but I can try to explain why your sites behave this way (we have very similar behaviour at our project). 我无法得到您提出的确切问题,但我可以尝试解释您的网站为何如此行事(我们的项目中的行为非常相似)。 I'm not sure it's 100% correct explanation of this behaviour but I ha AFAIK: 1. Your IIS and IIS Express can't use same port simultaneously. 我不确定这是对此行为的100%正确解释,但我知道AFAIK:1。您的IIS和IIS Express无法同时使用相同的端口。 2. Azure Compute Emulator running it's own stack\\Load balancing proxy ( to emulate multi-instance azure environment) and need to register itself on some port. 2. Azure Compute Emulator运行它自己的堆栈\\负载平衡代理(模拟多实例azure环境)并需要在某个端口上注册自己。

So why this stuff happens : You, probably have some other sites in your IIS, that using port 80. So when Emulator starting - it discovers that port 80 can't be used ( cause it's locked by your working iis). 那么为什么会发生这样的事情:你可能在你的IIS中有一些使用端口80的其他站点。所以当Emulator启动时 - 它发现端口80不能被使用(因为它被你的工作iis锁定)。 An it starts port-walking, until it find next free port to bind to (for us it'll be 81 and 444). 它开始移动端口,直到它找到下一个要绑定的自由端口(对我们来说它将是81和444)。 You can check General Output window after starting F5 and you can find similar messages there: 您可以在启动F5后检查“常规输出”窗口,您可以在那里找到类似的消息:

Windows Azure Tools: Warning: Remapping public port 80 to 81 to avoid conflict during emulation.
Windows Azure Tools: Warning: Remapping public port 443 to 444 to avoid conflict during emulation.
Windows Azure Tools: Warning: Remapping private port 80 to 82 in role 'MvcApplication' to avoid conflict during emulation.
Windows Azure Tools: Warning: Remapping private port 443 to 446 in role 'MvcApplication' to avoid conflict during emulation.

So emulator registered his load-balancing endpoint on public port 81\\444 and exposed some kind of internal endpoint on 82\\446. 因此,仿真器在公共端口81 \\ 444上注册了他的负载平衡端点,并在82 \\ 446上暴露了某种内部端点。 But I suspect that '127.0.0.1' and 'localhost' behave a bit differently (I know that it's the same thing, just suspect that IP url will go through a bit different pipeline, but I can't confirm my guesses) and, especially if you have multiple sites in one role - 127.0.0.1 won't be able to hit proper endpoint (maybe cause it's doesn't contain proper host header? ). 但我怀疑'127.0.0.1'和'localhost'的行为有点不同(我知道它是一样的,只是怀疑IP url会经历一个不同的管道,但我无法确认我的猜测),特别是如果你在一个角色中有多个站点 - 127.0.0.1将无法命中正确的端点(可能因为它没有包含正确的主机头?)。

This leads to the situation when localhost:444 (in our case) work correctly and 127.0.0.1:444 don't. 这导致localhost:444(在我们的例子中)正常工作而127.0.0.1:444不能正常工作的情况。

This answer also could lead you to some options how to fix\\deal with that. 这个答案也可以引导你找到一些选择如何解决问题。

Hope it'll help you a bit 希望它会对你有所帮助

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

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