How do you include .html or .asp file using razor?

后端 未结 14 1521
说谎
说谎 2020-12-14 01:09

Is it possible to use server side include in Razor view engine to include .html or .asp file? We have an .html file and .asp files that contain website menus that are used

14条回答
  •  情话喂你
    2020-12-14 01:33

    Try implementing this HTML helper:

    public static IHtmlString ServerSideInclude(this HtmlHelper helper, string serverPath)
    {
        var filePath = HttpContext.Current.Server.MapPath(serverPath);
    
        // load from file
        using (var streamReader = File.OpenText(filePath))
        {
            var markup = streamReader.ReadToEnd();
            return new HtmlString(markup);
        }
    }
    

    or:

    public static IHtmlString ServerSideInclude(this HtmlHelper helper, string serverPath)
    {
        var filePath = HttpContext.Current.Server.MapPath(serverPath);
    
        var markup = File.ReadAllText(filePath);
        return new HtmlString(markup);
    }
    

提交回复
热议问题