Метод остановки при запуске в API Visual Studio 2017 NetCore 2.2 - PullRequest
0 голосов
/ 05 ноября 2019

файл запуска и контроллер

     using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Net.Http.Headers;
    using System.Threading.Tasks;
    using Microsoft.AspNetCore.Http;
    using Microsoft.AspNetCore.Mvc;

    namespace photography.Controllers
    {
    [Route("api/[controller]")]
    [ApiController]
    public class UploadController : ControllerBase

    {
        [HttpPost, DisableRequestSizeLimit]
        public IActionResult Upload()
        {
            //try
            //{
                var files = Request.Form.Files;
                var folderName = Path.Combine("Resources", "Images");
                var pathToSave = Path.Combine(Directory.GetCurrentDirectory(),     folderName);

                if (files.Any(f => f.Length == 0))
                {
                    return BadRequest();
                }

                foreach (var file in files)
                {
                    var fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"');
                    var fullPath = Path.Combine(pathToSave, fileName);
                    var dbPath = Path.Combine(folderName, fileName); //you can add this path to a list and then return all dbPaths to the client if require

                    using (var stream = new FileStream(fullPath, FileMode.Create))
                    {
                        file.CopyTo(stream);
                    }
                }

                return Ok("All the files are successfully uploaded.");
            }
            //catch (Exception ex)
            //{
            //    return StatusCode(500, "Internal server error");
            //}
        //}
    }
    }

startupfile
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
    using System.Threading.Tasks;
    using Microsoft.AspNetCore.Builder;
    using Microsoft.AspNetCore.Hosting;
    using Microsoft.AspNetCore.Http;
    using Microsoft.AspNetCore.Mvc;
    using Microsoft.EntityFrameworkCore;
    using Microsoft.Extensions.Configuration;
    using Microsoft.Extensions.DependencyInjection;
    using Microsoft.Extensions.FileProviders;
    using Microsoft.Extensions.Logging;
    using Microsoft.Extensions.Options;
    using Newtonsoft.Json.Serialization;
    using photography.Models;

        namespace photography
        {
          public class Startup
        {
        public Startup(IConfiguration configuration)
        {
          Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

    // This method gets called by the runtime. Use this method to add     services         to the container.
    public void ConfigureServices(IServiceCollection services)
    {
                services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2).AddJ    sonOptions(options => {
                var resolver = options.SerializerSettings.ContractResolver;
                if (resolver != null)
                    (resolver as DefaultContractResolver).NamingStrategy = null;
            });
            services.AddDbContext<DbContextPhoto>(options =>
    options.UseSqlServer(Configuration.GetConnectionString("DevConnection")));


            services.AddCors();
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
      if (env.IsDevelopment())
      {
        app.UseDeveloperExceptionPage();
      }
            //else
            //{
            //    app.UseHsts();
            //}


            app.UseCors(options =>
        options.WithOrigins("http://localhost:4200")
        .AllowAnyMethod()
        .AllowAnyHeader());

            app.UseHttpsRedirection();



            app.UseStaticFiles();
            app.UseStaticFiles(new StaticFileOptions()
            {
                FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), @"Resources")),
                RequestPath = new PathString("/Resources")
            });

            app.UseMvc();
    }
  }
}

iis останавливается при запуске контроллера api

vs2017 .netCore 2.2

и

закрыть антивирус

и закройте брандмауэр

и запустите Visual Studio 2017 от администратора

и обновите его до последней версии

, но все загруженные изображения успешно **

по окончании остановка iis и остановка режима отладки автоматически usindg visual studio 2017 и angular 7 Как мне решить эту проблему?

**

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...