Projekt-Anfragen: Tel: 07022/9319004 info@CodeDocu.de Software Entwicklung in C# WPF Asp.Net Core Vba Excel Word SQL-Server EF Linq, UWP Net
#

 

Wie definiert man in Asp.Net Core MVC die Datei, mit welcher die Webseite gestartet werden soll?

 

Man legt in der Datei Startup.cs den Vorgang fest.

Die Festlegung findet in dem Block: app.UseMvc(routes=..) statt.

Dabei wird die erste URL-Route genommen, die fest zugewiesen ist.

Die allgemeine Adresse wird als default bezeichnet mit dem MVC Muster Controller/Action/ID.

 

Wenn eine Route mit festgelegten =Parametern vor der Default Anweisung eingefügt wird, dann springt der Start der Webseite auf die vorgeschobene Controller->Action

app.UseMvc(routes =>

{

    routes.MapRoute(

        name: "demo_02_Ajax_Image_Upload",

        template: "{area=demo_02}/{controller=Demo}/{action=demo_start}");

    routes.MapRoute(

        name: "default",

        template: "{controller=Home}/{action=Index}/{id?}");

}

);

 

 

 

 

Startup.cs

In Asp.Net Core MVC

using System;

using System.Collections.Generic;

using System.Linq;

using System.Threading.Tasks;

using Microsoft.AspNetCore.Builder;

using Microsoft.AspNetCore.Identity;

using Microsoft.EntityFrameworkCore;

using Microsoft.AspNetCore.Hosting;

using Microsoft.Extensions.Configuration;

using Microsoft.Extensions.DependencyInjection;

using IWois_Core.Data;

using IWois_Core.Models;

using IWois_Core.Services;

 

namespace IWois_Core

{

    public class Startup

    {

        public Startup(IConfiguration configuration)

        {

            Configuration = configuration;

        }

 

        public IConfiguration Configuration { get; }

 

        // This method gets called by the runtime. Use this method to add services to the container.

        public void ConfigureServices(IServiceCollection services)

        {

            services.AddDbContext<ApplicationDbContext>(options =>

                options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

           

            //services.Configure<ConnectionString>(Configuration.GetSection("ConnectionStrings"));

 

            services.AddIdentity<ApplicationUser, IdentityRole>()

                .AddEntityFrameworkStores<ApplicationDbContext>()

                .AddDefaultTokenProviders();

 

            // Add application services.

            services.AddTransient<IEmailSender, EmailSender>();

 

            services.AddMvc();

 

 

            //*init sql-server direct

            Database.SQL_Database.cn_String = Configuration.GetConnectionString("DefaultConnection");

           

        }

 

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.

        public void Configure(IApplicationBuilder app, IHostingEnvironment env)

        {

            if (env.IsDevelopment())

            {

                app.UseBrowserLink();

                app.UseDeveloperExceptionPage();

                app.UseDatabaseErrorPage();

            }

            else

            {

                app.UseExceptionHandler("/Home/Error");

            }

 

            app.UseStaticFiles();

 

            app.UseAuthentication();

 

            app.UseMvc(routes =>

            {

 

                routes.MapRoute(

                    name: "area",

                    template: "{area:exists}/{controller=Home}/{action=Index}/{id?}");

 

                routes.MapRoute(

                    name: "demo_02_Ajax_Image_Upload",

                    template: "{area=demo_02}/{controller=Demo}/{action=demo_start}");

 

 

 

                routes.MapRoute(

                   name: "Notes", // Route name

                   template: "Notes", // URL with parameters

                   defaults: new { controller = "Notes", action = "Index_all" }

               );

 

                routes.MapRoute(

                    name: "default",

                    template: "{controller=Home}/{action=Index}/{id?}");

 

            }

            );

 

 

            //seed dbContext

            Database.EF_Model.Initialize_DbContext_in_Startup(app.ApplicationServices);

        }

    }

}

 

 

 

 

Mobile
»
Asp Core Umleitung http zu https und www. Zu direkt Domain-Host
»
Asp MVC Core: URL Query Parameter
»
Asp Core MVC: neu Start-Datei definieren, Start Controller View
»
Asp MVC : HTML Links statt Asp Server Side Links
»
AmbiguousActionException: Multiple actions matched
»
Asp.Net Core MVC: Alternative URL Routen anlegen

.

Jobs, Projekte, Angebote für Freiberufler, Selbstständig an Info@CodeDocu.de