par*_*rag 5 asp.net asp.net-web-api asp.net-core-mvc asp.net-core
我有一个使用完整的.net 框架(.Net 4.6.1)在asp.net core 中开发的应用程序。该应用程序是使用 Visual Studio 2017 RC 创建的。编译成功后,生成了TestApplication.exe。
\n\n当我转到项目根目录并执行命令 dotnet run 时,应用程序将启动并开始侦听端口 5000。使用此方法应用程序运行良好。但是,当我转到projectRoot\\ bin\\Debug\\net461\\
并启动 TestApplicatin.exe 时,它也开始侦听端口 5000,但是当我转到浏览器并输入http://localhost:5000时,出现以下错误
\n\n\n本地主机页面\xe2\x80\x99t 正在工作
\n
localhost 当前无法处理此请求。
\n\nHTTP 错误 500
\n\n笔记-
\n\n请查看Program.cs文件的内容
\n\npublic static void Main(string[] args)\n {\n var host = new WebHostBuilder()\n .UseKestrel()\n .UseContentRoot(Directory.GetCurrentDirectory())\n .UseIISIntegration()\n .UseStartup<Startup>()\n .Build();\n\n host.Run();\n }\n
Run Code Online (Sandbox Code Playgroud)\n
发现问题了。我正在运行 exe 而不发布它。所以bin目录只包含exe(即TestApplication.exe),没有wwwroot文件夹。它无法找到所需的文件,因此发生了致命错误。如果您想在没有 IIS 的情况下运行 ASP.NET Core 应用程序(即使用 Kestrel 的自托管应用程序),以下是正确的步骤
从命令提示符启动 exe 或双击它。在我的例子中,发布 exe 后位于以下路径
bin\Debug\net461\win7-x86\publish\TestApplication.exe
归档时间: |
|
查看次数: |
12785 次 |
最近记录: |