小编ecm*_*dev的帖子

如何忽略MVC6中的路由

我正在开发一个非常简单的SPA风格的应用程序,我不想使用剃须刀,所以我只需要它来提供HTML文件(来自wwwroot文件夹),除了js调用我的API控制器.在Web API 2中,您可以让路由器忽略HTML文件,以便直接提供它们,例如

config.Routes.IgnoreRoute("Html", "{whatever}.html/{*pathInfo}");
Run Code Online (Sandbox Code Playgroud)

与此示例类似:http://www.strathweb.com/2014/04/ignoring-routes-asp-net-web-api/是IgnoreRoute功能尚未实现或是否已更改?

目前,如果我有app.UseMvc(); 在我的Startup.cs中,对"/"的任何get请求都会给我这个异常:

An unhandled exception occurred while processing the request.
InvalidOperationException: The view 'Index' was not found. The following     locations were searched:
/Views/Home/Index.cshtml
/Views/Shared/Index.cshtml.
Microsoft.AspNet.Mvc.Rendering.ViewEngineResult.EnsureSuccessful()
Run Code Online (Sandbox Code Playgroud)

但是当我离开它而没有MVC时,它会在你请求"/"时提供index.html文件 - 显然我的API控制器不会工作.

asp.net-core-mvc asp.net-core

15
推荐指数
2
解决办法
5082
查看次数

修改MVC 6的原始html输出

像webmarkupmin这样的插件使用HTTP模块从HTTPContext修改HTTP响应体,如下所示:

protected override void ProcessContent(HttpContext context)
    {
        HttpRequest request = context.Request;
        HttpResponse response = context.Response;
        Encoding encoding = response.ContentEncoding;
        string contentType = response.ContentType;

        if (request.HttpMethod == "GET" && response.StatusCode == 200
            && contentType == ContentType.Html
            && context.CurrentHandler != null)
        {
            var htmlMinifier = WebMarkupMinContext.Current.Markup.CreateHtmlMinifierInstance();
            response.Filter = new HtmlMinificationFilterStream(response.Filter, htmlMinifier,
                request.RawUrl, encoding);

            if (WebMarkupMinContext.Current.IsCopyrightHttpHeadersEnabled())
            {
                CopyrightHelper.AddHtmlMinificationPoweredByHttpHeader(response);
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

如何使用ASP.NET 5中的新HTTP管道修改每个请求的原始HTTP响应主体?

asp.net-core-mvc asp.net-core

3
推荐指数
1
解决办法
2327
查看次数

标签 统计

asp.net-core ×2

asp.net-core-mvc ×2