I'm trying to route to areas based on a subdomain while having the URL not include the Area parameter.

I'd like to be able to go the following routes for example

example1.domain.com/login

example1.domain.com/landingpage

example2.domain.com/login

example2.domain.com/landingpage

I'd like to have each subdomain route to a different Area. I've tried following this post Is it possible to make an ASP.NET MVC route based on a subdomain? which led me to http://benjii.me/2015/02/subdomain-routing-in-asp-net-mvc/. But I can't seem to figure out how to not have the Area parameter in the URL.

How can I get the correct URL schema I'm looking for? {subdomain}.domain.com/{action}/{id}

This question already has an answer here:

Hello StackOverflow members,

I have two controllers:

public class FirstController : Controller
{
    public string Index()
    {
        return "FirstController - Index";
    }
}

public class SecondController : Controller
{
    public string Index()
    {
        return "SecondController - " + language;
    }
}

And I have two URLs: 1. mysite.com/ 2. en.mysite.com/

I expect to get:

  1. FirstController - Index

  2. SecondController - en

where en can be any param.

How should I adjust my Global.asax to fix this issue:

public class MvcApplication : System.Web.HttpApplication
{
    protected void Application_Start()
    {
        RegisterRoutes(RouteTable.Routes);
    }

    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );
    }
}

This question already has an answer here:

Hello StackOverflow members,

I have two controllers:

public class FirstController : Controller
{
    public string Index()
    {
        return "FirstController - Index";
    }
}

public class SecondController : Controller
{
    public string Index()
    {
        return "SecondController - " + language;
    }
}

And I have two URLs: 1. mysite.com/ 2. en.mysite.com/

I expect to get:

  1. FirstController - Index

  2. SecondController - en

where en can be any param.

How should I adjust my Global.asax to fix this issue:

public class MvcApplication : System.Web.HttpApplication
{
    protected void Application_Start()
    {
        RegisterRoutes(RouteTable.Routes);
    }

    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );
    }
}

I'm an experienced .NET developer, making my first steps in .NET Core in the passed few days, more specific in building RESTful APIs using ASP.net Core.

I know there are 2 possible routing options - Convention Routing (traditional) vs the Attribute Based Routing (newer).

I've read that the ASP.net core's development team recommendation is to use Attribute Based Routing for APIs rather than the tradition Convention Based routing, which is more suitable for MVC applications.

I'd really like to understand - Why?

It seems that the attribute based routing makes us write more code ending up having the same behavior as the conventional routing.

I am working on angular application, i am using asp.net mvc(not .html page). in which i need dynamic menu + routing + i want to remove # from url. how to use .cshtml page as templates?is it possible?

i am using angular 1.5.0

i already tried below mentioned solutions but its not working for me. http://csharp-video-tutorials.blogspot.in/2016/02/remove-from-url-angularjs.html (this solution working fine for html templates but not for cshtml)

Is angular routing template url support for .cshtml file in ASP.Net MVC 5 Project?

please let me know if any one has solution for this problem.

Many Thanks.

Good.

I am making an application in ASP.NET MVC and publishing it does not work correctly because the paths are not correct.

Let's say it's published in

https://test.depruebas.es/jgs/p12/Chat The first login screen that is the one that starts the project shows it well, but when I give the button of the BeginForm of the form, I should send to the Home controller and action Index

  

 @using (Html.BeginForm ("Index", "Home", FormMethod.Post))

Pressing the button sets this route to me:

test.depruebas.es/Chat/Home/Index

but really should put

test.depruebas.es/jgs/p12/Chat/Home/Index

How can I specify that I get the subdomain of the route?

I understand that MVC and Web API (and off late it has even been included in the ASP.NET runtime to) have a routing engine that takes the URI and routes it to the right controller (or HttpHandler in the case of Web Forms).

But my question is -- the routing engine of MVC lives in a separate library, the MVC library. So even before the MVC routing engine comes to work, there must be something within the ASP.NET runtime that decides that the request is for MVC, so let's load the MVC library and then give the request to MVC's routing engine.

What component is that?

similar to https://stackoverflow.com/questions/5863984/asp-net-mvc-many-routes-always-only-one-controller#=

i have a .net 4.7 MVC project project

my config route are as follows (following from the above post)

      config.Routes.MapHttpRoute(
    name: "AllRoutes",
    routeTemplate: "{*url}",
    defaults: new
    {
      controller = "base",
    });

my base controller in my .net 4.7 project

public class BaseController : ApiController
{
  [HttpGet]
  public IHttpActionResult Get(HttpRequestMessage request)
  {
    return Ok();
  }

  [HttpPost]
  public IHttpActionResult Post(HttpRequestMessage request)
  {
    return Ok();
  }

  [HttpPut]
  public IHttpActionResult Put(HttpRequestMessage request)
  {
    return Ok();
  }

  [HttpDelete]
  public IHttpActionResult Delete(HttpRequestMessage request)
  {
    return Ok();
  }
}

now i'm porting my project into a .net Core 2.0

i can't seem to setup the same thing

my config in the .net core project are as follows

      app.UseMvc(routes =>
  {
    routes.MapRoute(
      name: "AllRoutes",
      template: "{*url}",
      defaults: new
      {
        controller = "Base"
      }
    );

my base controller for my .net core project

//[Route("api/[controller]")]
public class BaseController : Controller
{
  [HttpGet]
  public IActionResult Get()
  {
    return Ok("get success");
  }

  // POST api/values
  [HttpPost]
  public IActionResult Post([FromBody]string value)
  {
    return Ok("post success");
  }

  [HttpPut]
  public IActionResult Put([FromBody]string value)
  {
    return Ok("put success");
  }

  [HttpDelete]
  public IActionResult Delete()
  {
    return Ok("delete success");
  }
}

any ideas?

I am trying to implement some convention-based routing in my new .NET 5 API, based on how Rails does it. I'm putting all of my controllers in a different namespace for each version, for example Controllers/v1/MyController. The way this is done in the new .NET is different to how it was done in previous versions.

I'm looking for something as described in this article, but even after looking through the asp.net docs and reading this article on routing, I am no closer to a solution.

My controllers currently look like this:

namespace SaleboatApi.Controllers.v1
{
    [Route("api/v1/[controller]")]
    public class MyController : Controller {
    ...

but I feel like if this is done right, I won't need the Route annotation.

I have an application made up of three distinct components:

  1. A .Net WebApi 2 project that provides RESTful services for non-.Net clients (such as an iPhone app)
  2. A .Net MVC 5 project that provides a front-end web-based interface for my application. This project does NOT call the WebApi 2 services for data operations.
  3. An Objective-C-based iPhone app

I've been trying to find ways to set up real-time communications using some sort of messaging service. I've looked at various options, including RabbitMQ and Azure Service Queues and I've had little luck in finding a solution that provides .Net and iOS libraries, so I've landed on SignalR (I'll eventually set up an Azure Service Bus as a backplane for SignalR) along with the SignalR-Objective-C library.

The two .Net projects have their own implementations of .Net Identity authentication (using OAuth Bearer tokens). I'm trying to understand the proper way to authenticate the front-end .Net client (using Javascript) and the iOS app (using Objective-C) with the SignalR hub. I've placed the SignalR hub code in a separate .Net project and am running it under its own subdomain, so the authorization tokens generated by the .Net Web Api and the .Net MVC 5 projects won't work directly for the SignalR hub.

  1. What is the proper way of passing an authorization token to a SignalR hub from Javascript? Is it passed in via the querystring somehow?
  2. What is the proper way of passing an authorization token to a SignalR hub from the SignalR-Objective-C library?
  3. Have I approached the architecture (separating the SignalR hub into a separate project and subdomain from the other portions of the application) in a way that makes sense? Or should I be thinking of this another way?

I've been thinking of encrypting a concatenated form of the user's username, a nonce, and a datetime stamp in the MVC 5 application and in the Web Api 2 application; I'll store the nonce in a table with the user's username when I do so. Then, I'll provide the encrypted value to the client when a webpage loads or when the iOS app retrieves the value via an API call. I'll then push that encrypted string (possibly via querystring) to the SignalR hub when the web-based Javascript client or the iOS app submit a request to the hub. The hub can then use a custom authorization header to decrypt the encrypted value, and compare the nonce and username in the SQL table where I previously stored it.

This being said, I'm concerned about the performance of this approach (I'll be querying the database each time a message is sent to the SignalR hub and inserting a row into a table each time a SignalR connection is established) and the security of this approach (could someone just grab the encrypted string - though I am using SSL - and perform a replay attack).

Any suggestions, feedback, or insight would be helpful. I'm also open to alternative technologies (RabbitMQ, Azure Service Queues) to accomplish a similar goal of real-time communication between .Net and iOS client interfaces. Thank you!

I wrote a attribute route Route("Home/{category?}/{Subcategory?}/List") want to match the following examples /Home/C1/S1/List, /Home/C1/List, /Home/List

But only to match the first url, the optional parameter did not work. How to use a routing rule matches the above three examples?

public class HomeController : Controller
{
    public IActionResult Index()
    {
        return View();
    }

    [Route("Home/{category?}/{subcategory?}/List")]
    public IActionResult List(Category? category = null, SubCategory? subcategory = null)
    {
        return Content(category.ToString() + "/" + subcategory.ToString());
    }

    [Route("Home/{code}")]
    public IActionResult Detail(string code)
    {
        return Content(code);
    }
}


public enum Category
{
    C1,
    C2,
    C3,
    C4
}

public enum SubCategory
{
    S1,
    S2,
    S3,
    S4
}

Similar Questions

Routing optional parameters in ASP.NET MVC 5

MVC routing with one fixed action and controllers with multiple optional parameters