Нужно получить оставшуюю часть (*****) от url:
host/content/img/*******
Пытаюсь вывести в представление но там пусто.
Класс startup
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Mvc;
namespace SiteCore
{
public class Startup
{
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddRouting();
}
public void Configure(IApplicationBuilder app)
{
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{name}");
routes.MapRoute(
name: "img",
template: "{controller}/{action}/{name}");
});
}
}
}
контроллер
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;
// For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
namespace SiteCore.Controllers
{
public class ContentController : Controller
{
public IActionResult img(HttpContext context)
{
//var image = System.IO.File.OpenRead(@"D:\SiteCore\SiteCore\Content\img\blend_s\"+ s);
//return File(image, "image/jpeg");
var routeValues = context.GetRouteData().Values;
var action = routeValues["name"].ToString();
ViewBag.name = action;
return View();
}
}
}
код представления
<@{
Layout = null;
}
<!doctype html>
<html>
<head>
<title>Hello ASP.NET MVC Core</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width">
</head>
<body>
<h1>@ViewBag.name</h1>
</body>
</html>