相关疑难解决方法(0)

将global.asax迁移到ASP.NET 5

几天前.NET Core RC1已经发布了,我在阅读了很多关于它之后第一次试了一下,我喜欢它,但它有点不同.我正在尝试将一个小博客(内置MVC5)迁移到MVC 6和.NET Core.这并不难,但我真的很难重新创建我在MVC 5中完全相同的global.asax设置,ASP.NET 5不再具有global.asax所以我无法弄清楚大多数设置的替代品是什么是?

    protected void Application_Start()
    {
        ViewEngines.Engines.Clear();
        ViewEngines.Engines.Add(new RazorViewEngine());

        MvcHandler.DisableMvcResponseHeader = true;
        AntiForgeryConfig.SuppressXFrameOptionsHeader = true;

        BundleConfig.RegisterBundles(BundleTable.Bundles);
        RouteConfig.RegisterRoutes(RouteTable.Routes);
    }

    protected void Application_BeginRequest()
    {
        Response.AddHeader("X-Frame-Options", "DENY");
    }

    protected void Application_EndRequest()
    {
        if (Response.StatusCode != 301 && Response.StatusCode != 302) return;

        var targetUrl = Response.RedirectLocation.Replace("ReturnUrl", "url");
        Response.RedirectLocation = targetUrl;
    }

    protected void Application_AuthenticateRequest(object sender, EventArgs e)
    {
        string typeName;

        byte userType = (byte)(Context.Request.IsAuthenticated ? byte.Parse(User.Identity.Name.Split('|')[2]) : 1);

        switch (userType)
        {
            case 1: { typeName = "Client"; break; } …
Run Code Online (Sandbox Code Playgroud)

c# asp.net asp.net-mvc .net-core asp.net-core

11
推荐指数
2
解决办法
8267
查看次数

标签 统计

.net-core ×1

asp.net ×1

asp.net-core ×1

asp.net-mvc ×1

c# ×1