Categories
Uncategorized

3.0 onslaught –April.WebApi climbed from 2.2 to 3.0 net core

table of Contents

    Foreword

    Upgrading of the road

    test

    summary

Foreword

After Swagger before changes made adjustments, or else to start thinking about upgrading project had before, so it was a demo project, to do all kinds of tests (of course, because I was lazy), which compares with this today toss step.

Upgrading of the road

First, April.WebApi project right click -> Properties, the net core 2.2 before the upgrade to 3.0, then right for each Class Library project -> Properties, the net standard 2.0 upgrade to 2.1 (this should be nothing).

After the upgrade, we regenerate it, Hey, no error flattered.

Because there have been examples of works created before 3.0, so for this child or to adjust Startup under.

Question 1



Because after net core3.0, for Api may be adjusted (because no one had created Mvc project), so this place is no longer a vague Mvc use.

    Modified

Because part of the method was abandoned because 3.0 is a new beginning.



Well, finished modifying the startup files, we are happy to run it.

Question 2

Why are so hard at the beginning, we look at this error is a good cross-domain problem, now let AllowAll is not it, not because we have to allow all access, but also to bring Cookie, now let so we did.

  • 修改后

After modifying this issue, let us run the program.

Question 3

This is what the problem then, Session not let this play, is not the main problem now is it does not require a WebHost, Session implementation does not clear it should be, so we have to upgrade the upgrade, adjust the adjustment, others the project also requires the introduction of the next update.

  • 修改

This place because I see the error directly after this upgrade, there is no cut to figure, the upgrade of the library name Microsoft.VisualStudio.Web.CodeGeneration.Design.

Modify the Program as follows:

    public class Program
    {
        public static void Main(string[] args)
        {
            CreateHostBuilder(args).Build().Run();
        }

        public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.UseStartup();
                });
    }

    supplement

At the following execution, I found that using the Session there will be problems, what specific issues it, because more than 3.0 of a registered item, so the session code adjusted as follows, where attention under UseSession position to be in after Redirection.

        public void ConfigureServices(IServiceCollection services)
        {
            …
            #region Session
            services.AddDistributedMemoryCache();
            services.AddSession(options =>
            {
                options.Cookie.Name = "April.Session";
                options.IdleTimeout = TimeSpan.FromSeconds(2000);//设置session的过期时间
                options.Cookie.HttpOnly = true;//设置在浏览器不能通过js获得该cookie的值,实际场景根据自身需要
                options.Cookie.IsEssential = true;
            });
            #endregion
            …
        }
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            …
            app.UseHttpsRedirection();

            app.UseSession();

            app.UseRouting();
            …
        }

After editing, let’s run the program.

Question 4

    modify

I do not need this translation software can see, this is what let returned, emm.
    The problem I feel is probably not yet begun to expand 3.0, after all, just left or honestly want people to use the built-in DI bar, where my approach, can only be honestly changed back void, this code will no longer show up, it is not the best solution.

Let us forget just uncomfortable, it continues to run the program.

Question 5

The Ukrainian press pressure of a large I thought the browser collapse of it, a closer look, well, swagger thing, there is not much to say.

    modify
            3.0 attack changes with particular reference to the net core –Swagger

I think you can see a friendly Swagger when the reality gave me a slap.

Question 6

The question, still want to use the extended DI caused, AspectCore this child something being the first screen, and then follow-up to find a solution and then deal with it.

  • 修改

After more than a bunch of toss, we finally came Swagger welcome the way, it is not easy.

test

Why does this take, I do not understand, used to test the functionality of it, but here is not the shots, too much trouble (of course, only a simple test carried out before the next test method).

    log4 functioning

    swagger functioning

    cache function properly

    session function properly

    cookie function properly

    sqlsugar functioning

    aop log function properly

    redis functioning

    Blocker and an intermediate layer functioning

If I did not try to have problems, you can give me a message, because a person’s strength, after all, there is so little limited.

summary

When covering the original code, I thought for a moment, I feared that if someone with it, will not affects people after such coverage, but then I thought, well, this thing is afraid of nobody with it, tinker with their own things, or toss something good, to make progress toss, toss the brain active, toss …, compile it no longer tinker with new things that later on, huh direct net core3.0.

Leave a Reply