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 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.

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?

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!

Our ASP.NET MVC web application has a few different subdomains we use for testing and legacy code. The subdomains are:

  1. www.sitename.com (production site)
  2. test.sitename.com (testing)
  3. original.sitename.com (legacy code)
  4. staging.sitename.com (occasionally used to testing right before a deployment)

We purposefully have the forms authentication not using domain level cookies because we want the cookies to be unique across these different subdomains. The problem is, when people get a link to the root domain (sitename.com), it requires them to log in again to get a cookie, even though they're already logged in to www.sitename.com.

Is there a way to share the cookie between only www.sitename.com and sitename.com without the other subdomains being affected?

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

I would like to know if it's possible to write a rule in the Route.Config file that can encompass all actions within a single controller? I have read this article but it's a little bit above me (I have just started with url rewriting and routing and the terminology is not familiar).

I have managed to change one of my actions from mydomain.co.za/Trainee/Action?id=123 to mydomain.co.za/Trainee/Action/123 but I was hoping to be able to encompass all actions in the Trainee controller, such that you can have one rule to produce Trainee/Action1/123 or Trainee/Action2/123 This is the code I used:

        routes.MapRoute(
            name: "ActionRewrite",
            url: "Trainee/Action/{id}",
            defaults: new { controller = "Trainee", action = "Action" }
        );

On a side note, is it possible to hide the parameters in a URL as well, such that you can simply have mydomain.co.za/Action/ no matter what the user is doing?

I want to build a self host web application, that based on Katana with OWIN specification.
I need ASP.NET Web MVC combine with ASP.NET Web API, for difference situation.

For example, the sign in site will based on ASP.NET Web MVC and further sites on Angular JS, that why I have to use ASP.NET Web API.

After do research in web, I found out, that ASP.NET Web MVC does not run on Katana.

How can I solve my problem?

i need to change my URL in my project

i have article "http://localhost:43524/home/Books/2"

the name for this article= "buy books free"

i went change this URL To

"http://localhost:43524/home/Books/buy-books-free"

and like Customizing Routes in ASP.NET MVC

how use the article title in my URL > how make it ?