locked
simple question... RRS feed

  • Question

  • User-1326166559 posted

    Ok, so I have a simple .NET Core 2.0 application, that requires a login to view the page(s).  I have tried to set it up so that the login page is the first page you see when you go to the site.  This is working locally, but when I deploy it to our testing environment, it doesn't seem to resolve to the login page.  I'm sure this is something simple I'm missing, as I'm pretty new to .net core architecture.

    I'm actually not entirely sure which of these settings is working and which isn't :

    In startup.cs, I have

     app.UseMvc(routes =>
                {
                    routes.MapRoute(
                        name: "home",
                        template: "{controller=Account}/{action=Login}/{id?}");
                });

    and in launchsettings.json, I have

    "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
    "applicationUrl": "http://localhost:50472",
    "sslPort": 44319
    }
    },
    "profiles": {
    "IIS Express": {
    "commandName": "IISExpress",
    "launchBrowser": true,
    "launchUrl": "https://localhost:44319/Account/Login",
    "environmentVariables": {
    "ASPNETCORE_ENVIRONMENT": "Development"
    }
    },


    If I remove the "Account/Login" from the launchsettings file, it doesn't resolve to anything in the testing environment.

    What am I missing ?



    Thanks In Advance

    Tuesday, November 21, 2017 2:08 PM

Answers

  • User-376018714 posted

    hi

    launchsettings.json is a Visual Studio related thing. Its for VS to launch the IISexpress during your development time.

    For setting default files you can check this official documentation here: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/static-files. It has a section default files.

    In your case - i believe what needs to happen is - any route navigated needs to be told be authenticated first. You need to set authentication first, then use [Authorize] attribute all your controllers. When you make a request for "/", that will be resolved to your home controller and since home controller is having authorize attribute, asp.net pipeline will automatically route the user to your authentication page. 

    launchsettings is never used in production. its just a developer thing.

    read up on asp.net core authentication here: https://docs.microsoft.com/en-us/aspnet/core/security/authentication/identity?tabs=visual-studio%2Caspnetcore2x

    the above doc has a section on how to set up authentication.

    hope this helps.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, November 22, 2017 5:16 AM

All replies

  • User-376018714 posted

    hi

    launchsettings.json is a Visual Studio related thing. Its for VS to launch the IISexpress during your development time.

    For setting default files you can check this official documentation here: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/static-files. It has a section default files.

    In your case - i believe what needs to happen is - any route navigated needs to be told be authenticated first. You need to set authentication first, then use [Authorize] attribute all your controllers. When you make a request for "/", that will be resolved to your home controller and since home controller is having authorize attribute, asp.net pipeline will automatically route the user to your authentication page. 

    launchsettings is never used in production. its just a developer thing.

    read up on asp.net core authentication here: https://docs.microsoft.com/en-us/aspnet/core/security/authentication/identity?tabs=visual-studio%2Caspnetcore2x

    the above doc has a section on how to set up authentication.

    hope this helps.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, November 22, 2017 5:16 AM
  • User-832373396 posted

    <g class="gr_ gr_8 gr-alert gr_gramm gr_inline_cards gr_run_anim Punctuation only-ins replaceWithoutSep" id="8" data-gr-id="8">Hi</g> <g class="gr_ gr_5 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling" id="5" data-gr-id="5">thedotnetguy</g>,

    so that the login page is the first page you see when you go to the site. 

    Only change your code to this as shown below in <g class="gr_ gr_237 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" id="237" data-gr-id="237">Starup</g>.cs, then everything should be ok!

      public void Configure(IApplicationBuilder app, IHostingEnvironment env)
            {
                if (env.IsDevelopment())
                {
                    app.UseDeveloperExceptionPage();
                    app.UseBrowserLink();
                    app.UseDatabaseErrorPage();
                }
                else
                {
                    app.UseExceptionHandler("/Home/Error");
                }
    
                app.UseStaticFiles();
    
                app.UseAuthentication();
    
                app.UseMvc(routes =>
                {
                    routes.MapRoute(
                        name: "default",
                        template: "{controller=Account}/{action=Login}/{id?}");
    }); }

    So

    but when I deploy it to our testing environment, it doesn't seem to resolve to the login page

    May I know which page it open? or get any error??

    With regards, Angelina Jolie

    Wednesday, November 22, 2017 10:11 AM
  • User-1326166559 posted

    This is exactly what I was looking for, thank you.

    Wednesday, November 22, 2017 2:47 PM