如何配置 MVC6 应用程序以在 IIS 上运行? [英] How to configure an MVC6 app to work on IIS?
问题描述
所以我在 Visual Studio 2015 中构建了一个 MVC6 应用程序,并且已经设法解决了大部分问题,但是,我还没有进行部署.
So I'm building an MVC6 app in Visual Studio 2015 and have managed to figure most stuff out, however, I haven't yet worked out deployment.
在 MVC4(我之前使用的)中,我们的流程*被发布到一个文件夹,然后在 IIS 中设置网站(右键单击 Sites
-> Add Website代码>).
In MVC4 (what I was using before), our process* was publish to a folder, then setup the website in IIS (Right-Click on Sites
-> Add Website
).
- 实际上,我们的流程是在 IIS 和 TeamCity 中设置的,但不适用于这样的测试应用程序:).
我遵循了这个过程,显然设置 IIS 网站并发布到正确的文件夹很简单......但这实际上对我不起作用.
I followed this process and obviously it's trivial to setup the IIS website and publish to the correct folder...but that does not actually work for me.
我们在 Windows Server 2012 上运行 IIS 8,并在服务器上安装了 .Net 4.6 运行时.
We're running IIS 8 on Windows Server 2012 and we've installed the .Net 4.6 runtime on the server.
推荐答案
以下步骤对我有用,应该可以帮助您在 IIS 上托管您的项目.
The following steps have worked for me and should help you host your project on IIS.
使用 Visual Studio 2015 Preview 作为您的 IDE,
Using Visual Studio 2015 Preview as your IDE,
- 创建一个 ASP .NET 5 Starter App.
- 检查它是否在 IIS 之外工作.
完成后,发布应用程序.在此示例中,我选择了位置
C:PublishWebApp
.
3.1.发布您的应用程序时,请确保您拥有:
3.1. When publishing your application, make sure that you have:
- 禁用预编译
选择amd64
- Disabled precompilation
Selected amd64
(见下图)
- 成功发布后,转到
C:PublishWebApp
.您应该会在其中看到文件夹approot
和wwwroot
. - 现在打开 IIS 管理器(我假设您已启用 ASP .NET 4.5 功能)
创建一个新网站.
- Upon a successful publish, go to
C:PublishWebApp
.You should see the foldersapproot
andwwwroot
inside. - Now open the IIS Manager (I am assuming you have the ASP .NET 4.5 feature enabled)
Create a new website.
6.1:选择wwwroot
文件夹作为网站的物理路径.在此示例中,它是 C:PublishWebAppwwwroot
.
6.1 : Select the wwwrooot
folder as the website's physical path. In this example, it is C:PublishWebAppwwwroot
.
检查网站以查看其是否正常工作.如果您遇到任何错误,请在此处发布.
Check the website to see that it is working. If you encounter any errors, please post them here.
如果在上图的 Publish Web Settings 窗口中勾选了预编译选项,那么您必须
If the precompile option is ticked in the Publish Web Settings window pictured above, then you must
- 转到您已发布的 Web 应用程序的
wwwroot
文件夹.在此示例中,它是C:PublishWebAppwwwroot
. - 找到
web.config
. 在您发布的应用程序的文件夹内,
approot
文件夹内有一个packages
文件夹,其中应包含一个以您的应用程序命名的文件夹,并带有一个文件夹下的版本.该文件夹内应该是一个名为root
的文件夹.在web.config
中,将键kre-app-base
的值设置为root
文件夹.作为参考,请参见下面的代码行.在本例中,应用程序名称为 WebApplication10.
- Go to the
wwwroot
folder of your published web application. In this example, it isC:PublishWebAppwwwroot
. - Locate
web.config
. Inside the folder of your published application, there is an
packages
folder inside of theapproot
folder which should contain a folder named after your application, with a folder for the version underneath. Inside that folder should be a folder namedroot
. Inweb.config
, set the value for the keykre-app-base
to theroot
folder. For reference, see the line of code below. In this example, the application name is WebApplication10.
<add key="kre-app-base" value="..approotpackagesWebApplication101.0.0
oot" />
这篇关于如何配置 MVC6 应用程序以在 IIS 上运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!