Skip to content

Commit

Permalink
Implementing app.UseMvc(configureRoutes); costumer routes
Browse files Browse the repository at this point in the history
  • Loading branch information
fMATSINHE committed Jan 4, 2020
1 parent cde61a5 commit 38b70b5
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 9 deletions.
9 changes: 3 additions & 6 deletions Helloword_core/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,15 @@

namespace Helloword_core.Controllers
{
[Route("Home")]

public class HomeController : Controller
{
[Route("")]
[Route("Index")]
{
// GET: /<controller>/
public string Index()
{
return "Hello from HomeController";
}

[Route("About")]

public string About()
{
return "About";
Expand Down
25 changes: 25 additions & 0 deletions Helloword_core/Controllers/ProductController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;

// For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace Helloword_core.Controllers
{

[Route("[Controller]/[Action]")]
public class ProductController : Controller
{
// GET: /<controller>/
public List<string> Index()
{
return new List<string>()
{
"Item 1",
"Item 2"
};
}
}
}
20 changes: 20 additions & 0 deletions Helloword_core/Controllers/UserController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;

// For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace Helloword_core.Controllers
{

public class UserController : Controller
{
// GET: /<controller>/
public string Index()
{
return "from User Index";
}
}
}
18 changes: 15 additions & 3 deletions Helloword_core/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

Expand All @@ -29,7 +30,8 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILogger<
}

app.UseStaticFiles();
app.UseMvcWithDefaultRoute();
app.UseMvc(configureRoutes);

app.Map("/test", testPipeline);
app.Use(next => async context =>
{
Expand All @@ -39,11 +41,11 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILogger<

app.Run(async (context) =>
{
logger.LogInformation("Response Served.");
logger.LogInformation("Response Served.");
await context.Response.WriteAsync(hello.SayHello());
});
}

#region testPipelines
private void testPipeline(IApplicationBuilder app)
{
app.MapWhen(context => { return context.Request.Query.ContainsKey("ln"); }, testPipeline1);
Expand Down Expand Up @@ -71,5 +73,15 @@ private void testPipeline2(IApplicationBuilder app)
await context.Response.WriteAsync("hello from teste testPipeline2 kay in;");
});
}
#endregion


private static void configureRoutes(IRouteBuilder routes)
{
routes.MapRoute("default", "{controller=Home}/{action=Index}/{id?}");
routes.MapRoute("admin", "admin/{controller=User}/{action=Index}/{id?}");
routes.MapRoute("shop", "{controller=Product}/{action=Index}/{id?}");

}
}
}

0 comments on commit 38b70b5

Please sign in to comment.