在ASP.NET MVC中提供favicon.ico的方法如下:
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
// 添加以下代码
RouteTable.Routes.MapRoute(
name: "favicon",
url: "favicon.ico",
defaults: new { controller = "Content", action = "Favicon" }
);
}
public class ContentController : Controller
{
[HttpGet]
public ActionResult Favicon()
{
return File("~/Content/favicon.ico", "image/x-icon");
}
}
以上就是在ASP.NET MVC中提供favicon.ico的方法。
领取专属 10元无门槛券
手把手带您无忧上云