HTTP错误500:本地主机当前无法处理此请求 [英] HTTP Error 500: localhost is currently unable to handle this request

查看:2272
本文介绍了HTTP错误500:本地主机当前无法处理此请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到HTPP错误500,但不确定为什么。启动服务时,我会弹出一个Chrome浏览器,并导航到 http:// localhost:5000 ,并弹出错误消息。 Chrome开发者工具窗口显示以下单个错误:

I'm running into an HTPP Error 500 and I'm not sure why. When I start my service, I pop open a Chrome browser and navigate to http://localhost:5000, and the error pops up. The Chrome Developer Tools windows shows this single error:

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

这是我的Startup.cs文件(使用语句排除为简单起见):

Here is my Startup.cs file (exluding using statements for simplicity):

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.");
            });
        }
    }
}

使用MVC,这会导致要调用的HomeController索引方法:

With MVC, this causes the HomeController Index method to get called:

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;
        }
    }
}

这是我的索引。 cshtml文件(已放置在视图 /首页中):

and here is my Index.cshtml file (which has been placed in 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>


推荐答案

像我一样,您可能需要安装ASP。 NET!

You, like me, might need to install ASP.NET!

在Windows Server 2012 R2上,这可以通过打开或关闭Windows功能功能来完成:

On Windows Server 2012 R2 this can be done via the Turn Windows features on or off feature:


  1. 完成以下步骤中的 安装类型服务器选择步骤

  2. 服务器角色下,找到 Web服务器(IIS)节点并展开它。

  3. 扩展 Web服务器节点。

  4. 扩展 Application Development 节点。

  5. 视情况检查 ASP.NET 3.5 ASP.NET 4.5 节点。

  6. 完成添加角色和功能向导

  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.
  3. Expand the Web Server node.
  4. Expand the Application Development node.
  5. Check the ASP.NET 3.5 or ASP.NET 4.5 nodes, as appropriate.
  6. Finish the Add Roles and Features Wizard.

这篇关于HTTP错误500:本地主机当前无法处理此请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆