简体   繁体   English

HTTP 错误 500:本地主机当前无法处理此请求

[英]HTTP Error 500: localhost is currently unable to handle this request

I'm running into an HTPP Error 500 and I'm not sure why.我遇到了 HTPP 错误 500,但不知道为什么。 When I start my service, I pop open a Chrome browser and navigate to http://localhost:5000 , and the error pops up.当我启动我的服务时,我弹出一个 Chrome 浏览器并导航到http://localhost:5000 ,并弹出错误。 The Chrome Developer Tools windows shows this single error: Chrome 开发者工具窗口显示了这个错误:

Failed to load resource: the server responded with a status of 500 (Internal Server Error) http://localhost:5000/

Here is my Startup.cs file (exluding using statements for simplicity):这是我的 Startup.cs 文件(为简单起见,不包括 using 语句):

namespace Tuner
{
    public class Startup
    {
        public static void Main(string[] args)
        {
            var exePath = Process.GetCurrentProcess().MainModule.FileName;
            var directoryPath = Path.GetDirectoryName(exePath);

                                var host = new WebHostBuilder()
               .CaptureStartupErrors(true)
               .UseKestrel()
               .UseUrls("http://localhost:5000")
               .UseContentRoot(Directory.GetCurrentDirectory())
               .UseIISIntegration()
               .UseStartup<Startup>()
               .Build();
            host.Run();
        }


        public Startup(IHostingEnvironment env)
        {
            //Setup Logger
            Log.Logger = new LoggerConfiguration()
                .WriteTo.Trace()
                .MinimumLevel.Debug()
                .CreateLogger();
            // Set up configuration sources.
            var builder = new ConfigurationBuilder()
                .SetBasePath(env.ContentRootPath)
                .AddJsonFile("appsettings.json");
            //.AddEnvironmentVariables();
            Configuration = builder.Build();
        }

        public IConfigurationRoot Configuration { get; set; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddSwaggerGen();

            services.AddMvc().AddJsonOptions(options =>
            {
                options.SerializerSettings.ContractResolver =
                    new CamelCasePropertyNamesContractResolver();
            });
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IApplicationLifetime lifetime)
        {

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}");
            });


            lifetime.ApplicationStopping.Register(() =>
            {
                Log.Debug("Application Stopping. Do stuff.");
            });
        }
    }
}

With MVC, this causes the HomeController Index method to get called:使用 MVC,这会导致 HomeController Index 方法被调用:

namespace Tuner.Controllers
{
    public class HomeController : Controller
    {
        public string appVersion = typeof(HomeController).Assembly.GetName().Version.ToString();
        public string appName = "Empty Web App";

        [HttpGet("/")]
        public IActionResult Index()
        {
            var url = Request.Path.Value;
            if (url.EndsWith(".ico") || url.EndsWith(".map"))
            {
                return new StatusCodeResult(404);
            }
            else
            {
                // else block is reached
                return View("~/Views/Home/Index.cshtml");
            }
        }

        public IActionResult Error()
        {
            return View("~/Views/Shared/Error.cshtml");
        }

        [HttpGetAttribute("app/version")]
        public string Version()
        {
            return appVersion;

        }

        [HttpGetAttribute("app/name")]
        public string ProjectName()
        {
            return appName;
        }
    }
}

and here is my Index.cshtml file (which has been placed in Views/Home):这是我的 Index.cshtml 文件(已放置在 Views/Home 中):

@{
    ViewBag.Title = "Tuner";
}

@section pageHead {
}

@section scripts {
    <script src="~/vendor.bundle.js"></script> 
    <script src="~/main.bundle.js"></script>

}

<cache vary-by="@Context.Request.Path">
    <app>Loading content...</app>
</cache>

I got the following error hosing an ASP.NET Core 3.1 application on IIS 10.0 after following this guide:遵循本指南后,我在 IIS 10.0 上托管 ASP.NET Core 3.1 应用程序时出现以下错误:

https://docs.microsoft.com/en-us/aspnet/core/tutorials/publish-to-iis?view=aspnetcore-3.1&tabs=visual-studio https://docs.microsoft.com/en-us/aspnet/core/tutorials/publish-to-iis?view=aspnetcore-3.1&tabs=visual-studio

This page isn't working
localhost is currently unable to handle this request.
HTTP ERROR 500

在此处输入图片说明

If you are on Windows:如果您使用的是 Windows:

Start Event Viewer -> Windows Logs -> Application.启动事件查看器 -> Windows 日志 -> 应用程序。

在此处输入图片说明

In my case I had the error below and could continue from there (Allow my Application Pool User to access localdb).在我的情况下,我有下面的错误,可以从那里继续(允许我的应用程序池用户访问 localdb)。

Microsoft.Data.SqlClient.SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. Microsoft.Data.SqlClient.SqlException (0x80131904):建立与 SQL Server 的连接时发生与网络相关或特定于实例的错误。 The server was not found or was not accessible.服务器未找到或无法访问。 Verify that the instance name is correct and that SQL Server is configured to allow remote connections.验证实例名称是否正确以及 SQL Server 是否配置为允许远程连接。 (provider: SQL Network Interfaces, error: 50 -Local Database Runtime error occurred. Cannot create an automatic instance. See the Windows Application event log for error details. (提供程序:SQL 网络接口,错误:50 - 发生本地数据库运行时错误。无法创建自动实例。有关错误详细信息,请参阅 Windows 应用程序事件日志。

You, like me, might need to install ASP.NET!您和我一样,可能需要安装 ASP.NET!

On Windows Server 2012 R2 this can be done via the Turn Windows features on or off feature:在 Windows Server 2012 R2 上,这可以通过打开或关闭 Windows 功能来完成:

  1. Complete the Before You Begin , Installation Type , and Server Selection steps of the wizard.完成向导的开始之前安装类型服务器选择步骤。
  2. Under Server Roles , find the Web Server (IIS) node and expand it.Server Roles 下,找到Web Server (IIS)节点并展开它。
  3. Expand the Web Server node.展开Web 服务器节点。
  4. Expand the Application Development node.展开应用程序开发节点。
  5. Check the ASP.NET 3.5 or ASP.NET 4.5 nodes, as appropriate.根据需要检查ASP.NET 3.5ASP.NET 4.5节点。
  6. Finish the Add Roles and Features Wizard .完成添加角色和功能向导

In your setup the UseIISIntegration "interferes" with UseUrls, as the UseUrls setting is for the Kestrel process and not the IISExpress/IIS.在您的设置中,UseIISIntegration “干扰”了 UseUrls,因为 UseUrls 设置用于 Kestrel 进程而不是 IISExpress/IIS。

If you want to change the IIS Port, have a look at Properties/launchSettings.json - there you can configure the applicationUrl IIS is using.如果您想更改 IIS 端口,请查看 Properties/launchSettings.json - 在那里您可以配置 IIS 正在使用的 applicationUrl。

You could remove the UseIISIntegration for testing purposes and then you can connect to Port 5000, but you never should use Kestrel as Internet facing Server, it should always be run behind a Reverse Proxy like IIS or Nginx, etc.您可以删除 UseIISIntegration 以进行测试,然后您可以连接到端口 5000,但您永远不应将 Kestrel 用作面向 Internet 的服务器,它应该始终在反向代理(如 IIS 或 Nginx 等)之后运行。

See the Hosting Docs Page for more information.有关更多信息,请参阅托管文档页面

I was using IIS (I'm unclear if OP was trying to use IIS), but I did not Install the .NET Core Windows Server Hosting bundle , as described in instructions like this one .我正在使用 IIS(我不清楚 OP 是否尝试使用 IIS),但我没有安装 .NET Core Windows Server Hosting bundle如本说明中所述。 After installing that Module, my app served (ie no 500 error)安装该模块后,我的应用程序提供服务(即没有 500 错误)

Run asp.net MVC core 1.1 project in vs2017 also get this error.在 vs2017 中运行 asp.net MVC core 1.1 项目也得到这个错误。
Solved by upgrade all NuGet Packages version 1.x to latest 2.x and target framework to .NET Core 2.1.通过将所有 NuGet 包版本 1.x 升级到最新的 2.x 并将目标框架升级到 .NET Core 2.1 来解决。

kindly check database once.请检查数据库一次。 In my condition I got issue in asp boilerplate.在我的情况下,我在 asp 样板中遇到了问题。 VS17 .net sdk version 2.2 . VS17 .net sdk 2.2 版。 just change in app setting file and add any working database and try to run project again.只需更改应用程序设置文件并添加任何工作数据库并尝试再次运行项目。

One possible reason is that you're trying to pass a PageModel as a parameter.一个可能的原因是您试图将 PageModel 作为参数传递。 For some reason, that fails:出于某种原因,这失败了:

System.NotSupportedException: The collection type 'Microsoft.AspNetCore.Mvc.ViewFeatures.ITempDataDictionary' on 'GT.ADS.Web.Pages.Error1Model.TempData' is not supported. System.NotSupportedException:不支持“GT.ADS.Web.Pages.Error1Model.TempData”上的集合类型“Microsoft.AspNetCore.Mvc.ViewFeatures.ITempDataDictionary”。

That should be common enough if you try to migrate from standard MVC architecture into Blazor setup.如果您尝试从标准 MVC 架构迁移到 Blazor 设置,这应该很常见。 After I passed what I needed from the model, the error was resolved.在我从模型中传递了我需要的东西后,错误就解决了。

暂无
暂无

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

相关问题 在IIS中部署WCF服务错误-“本地主机当前无法处理此请求” - Deploy WCF service in IIS error - “localhost is currently unable to handle this request” 如何为WCF Web角色配置消息大小(当前获得HTTP错误代码500) - How to configure the message size for a WCF web role (Currently getting HTTP error code 500) 代理错误:无法将请求从 localhost:3000 代理到 http://localhost:44381/ (ECONNREFUSED) - Proxy error: Could not proxy request from localhost:3000 to http://localhost:44381/ (ECONNREFUSED) 从 http 访问 WCF 服务时出现 500 内部服务器错误并且由于相同原因无法添加服务引用 - 500 Internal Server error while accessing WCF service from http and unable to add service reference for the same reason 在Azure辅助角色http请求中获取http 500 - Get http 500 in a Azure worker role http request 不断收到“Exchange Web 服务当前不可用于此请求,因为”错误? - Keep getting "Exchange Web Services are not currently available for this request because" error? 来自来源&#39;http:// localhost:&#39;的localhost:/ token请求已被CORS阻止 - Request at localhost:/token from origin 'http://localhost:' has been blocked by CORS SignalR与Mono和apache一起运行:HTTP 500错误(在SignalR代码中) - SignalR run with Mono and apache: HTTP 500 error (in SignalR code) Facebook OAuth:回调URI给我一个HTTP错误500 - Facebook OAuth: Callback URI gives me an HTTP ERROR 500 AppHarbor MVC3应用程序引发HTTP500错误 - AppHarbor MVC3 application throws HTTP500 error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM