仅当将MVC应用程序部署到IIS时,索引和Json路由才会出现问题吗?

时间:2019-11-28 04:17:22

标签: .net asp.net-core iis localhost

我正在使用.net core 3.0 mvc

使用IIS Express在Visual Studio中启动应用程序

我在localhost / Weather处有一个索引

我在localhost / Weather / Currents / {userId}

处有一个json获取

一切都像魅力一样

将应用程序发布到C:/ Websites / CodingLibrary

启动IIS

创建新站点

网站:端口80上的编码库

修改后的Hosts文件以查看站点127.0.0.1编码库的本地文件系统

打开Chrome

类型编码库

我的网站打开

我去编码图书馆/天气

它进入了站点

我的Index.js文件已加载,并开始调用encoding-library / Weather / Currents / {userId} GET Json Route

我使用Fetch Api

container.innerHTML = WeatherComponent.DisplayWeather(await (await fetch(`/Weather/Currents/${userId}`, { method: 'GET' })).json());

404未找到

我不知道该怎么办

[Route("Weather")]
public class WeatherController : BaseController<WeatherService>
{
    public WeatherController(WeatherService service) : base(service) { }

    public IActionResult Index() =>
        View();

    [HttpGet("Locations")]
    public async Task<IActionResult> SearchWeatherLocationsAsync(string search) =>
        Ok(await _service.SearchWeatherLocationsAsync(search));

    [HttpGet("Currents/{userId}")]
    public async Task<IActionResult> GetCurrentWeatherAsync(int userId, int? weatherLocationId, decimal? latitude, decimal? longitude) =>
        Ok(await _service.GetWeatherCurrentAsync(userId, weatherLocationId, latitude, longitude));
}

}

enter image description here

--------------------------------------------------- -----------------------------

enter image description here

0 个答案:

没有答案