ASP.Net Core/AngularJS: Routing problems showing "/#!/" directory - c#

I'm developing an ASP.Net Core Application that uses AngularJS (version 1). I've got a problem that when I run/launch the application, the home URL always comes out to:
http://localhost:59745/#!/
The specific question I have is towards why it's saying /#!/ and not just the expected root /.
My Startup.cs that declares the MapRoute for the application:
app.UseMvc(config =>
{
config.MapRoute(
name: "Default",
template: "{controller}/{action}/{id?}",
defaults: new { controller = "App", action = "Index" }
);
});
My app.js declaring the angular seeding for the application/module:
var app = angular.module('myScheduler', ['ngStorage', 'ngRoute'])
.config(function ($routeProvider) {
$routeProvider.when("/", {
controller: "homeController",
controllerAs: "vm",
templateUrl: "/views/home.html"
});
$routeProvider.otherwise({
controller: "loginController",
controllerAs: "vm",
templateUrl: "/views/login.html"
});
});
Why is my URL showing the way it is, and how can I default it to just the root / rather than /#!/?

Related

How do you remove shared hosting folder name from URL in ASP.NET Core 2?

I have a website (http://jsoncore.net) that I am using to learn .NET Core 2 and I want to remove the shared hosting folder name from the URL that is added to links and sources. For example I add an Html.ActionLink like this:
#Html.ActionLink(page.NavTitle, page.Slug, "Home")
and the system writes it to this:
Blog
I want to remove the "/jsoncore" from the link URL so that it should look like this:
Blog
Here are the routes defined in Startup.cs:
app.UseMvc(routes =>
{
routes.MapRoute(
"AdminController",
"Admin/{action}",
new { controller = "Admin", action = "Index"}
);
routes.MapRoute(
"BlogController-BlogHome",
"Blog/",
new { controller = "Blog", action = "Index" }
);
routes.MapRoute(
"BlogController-Post",
"Post/{id}",
new { controller = "Blog", action = "Post", id = "" }
);
routes.MapRoute(
"BlogController-Post-Tag",
"Blog/Tag/{id}",
new { controller = "Blog", action = "Tag", id = "" }
);
routes.MapRoute(
"BlogController-Post-Category",
"Blog/Category/{id}",
new { controller = "Blog", action = "Category", id = "" }
);
routes.MapRoute(
"HomeController",
"{action}/{id}",
new { controller = "Home", action = "Index", id = "id?" }
);
routes.MapRoute("AccountController", "Login", new { controller = "Account", action = "Login"});
routes.MapRoute("page", "{id}", new { controller = "Home", action = "Page", url = "" });
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
If the site is hosted in a virtual directory /jsoncore/ there's no way to remove that from the URL, as it's actually part of the URL, i.e. you need that to get to the right place. Otherwise, the requests would hit the site hosted at just http://jsoncore.net, which isn't this application. It's called a Universal Resource Locator for a reason. Only the correct URL will work, which includes the /jsoncore/ part, apparently.
Some shared hosting lets you bind to a domain or subdomain (although there'd probably be an upcharge for that). If that's available, that would be your best bet. Then, you can effectively host your site at the root of that domain/subdomain, without needing a path prefix.

Routing system uses default route instead of specific one

I have problem with routing in my mvc app. I have my core app with ProductsController and extension that is loaded in "PreApplicationStartMethod". In this extenstion i register route like this:
routes.MapRoute(
name: "ProductDetails",
url: "Products/Details/{id}",
defaults: new { controller = "StandardProductsDetails", action = "Details" },
namespaces: new []{ "Shop.Controllers" }
);
And in my core app im not registering specific route for ProductsController but I have a general route:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
namespaces: new[] { "Shop.Controllers" }
);
Now when I enter /Products/Details/1 in web browser im redirectd to ProductsController.
Oderd of adding routes is specific first, general last. I've checked routes table and my route is existing in it.
I think you are using two projects here, if you are using then make the project as startup project(by right click) which you want to hit first.

MVC 4 ASP.net 4.5 ... 404 Error & angular routing - IIS 8.5 and windows 8.1

I have searched everything under the sun! It is driving me insane. I have set up a MVC 4.0 application on IIS 8.5 on windows 8.1 and getting 404 error when routing. Below is my routing defined:
routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{action}",
defaults: new { action = RouteParameter.Optional }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
i' ve added: runAllManagedModulesForAllRequests="true" in web.config but no use!
i want controller/view to work e.g
<a href ='Controller/View'>Home</a>
the routing via
<a href='#Url.Action("View", "Home")'>Home</a>
this works but my angular module loading/routing fails! My angular is set up as below:
.config(function ($stateProvider, $urlRouterProvider) {
$stateProvider
.state(
"main", {
url: "/",
views: {
'': { templateUrl: '/Partials/MainTemp.html' },
//Menu
'columnOne#main': {
templateUrl: '/Partials/Menu.html',
controller: 'menuCtrl'
},
//Page
'columnTwo#main': {
templateUrl: '/Partials/MainPage.html',
controller: 'mainCtrl'
}
}
})
Everything works fine in debug mode. Am i missing something very basic!

Redirect from .aspx url to .aspx page

I'm updating my asp.net page from asp.net 2.0 to MVC4.
What I'm trying to do is to basically keep supporting the existing url:
mypage.com/one.aspx to be backwards compatible, except that I want to put all aspx pages in a aspx directory, so the new url would be mypage.com/aspx/one.aspx.
If I type the url directly mypage.com/aspx/one.aspx it works and the page comes up.
Now I'm trying to use RouteConfig to tell it to redirect one.aspx to aspx/one.aspx, but I see no way on how to do it. All RouteConfig examples I see use controllers, which is not what I want to do:
routes.MapRoute(name: "ONE", url: "one.aspx", defaults: new { controller = "Home", action = "Index" });
Is there a way to use MapRoute in RouteConfig to redirect to another aspx page? I'm using C# with MVC4.
This must work:
routes.MapPageRoute("aspx-redirection", "{page}.aspx", "~/aspx/{page}.aspx");
There is ...
but it's not directly from MapRoute
routes.MapRoute(
name: "Legacy",
url: "aspx222/{page}.aspx",
defaults: new { controller = "Home", action = "Page", page = UrlParameter.Optional }
);
And after in Home in Page
public ActionResult Page(string page)
{
return Redirect(String.Format("/aspx/{0}.aspx",page));
}

Controller is taken from Url although no controller is requested in URL - c# .Net MVC 4

I'm currently working at a .NET 4.5 MVC 4 Web Application.
I have got the following Routes:
routes.MapRoute(
name: "Default",
url: "api/",
defaults: new { controller = "Response", action = "ReturnAllStations" }
);
routes.MapRoute(
name: "ID",
url: "api/{id}",
defaults: new { controller = "Response", action = "ReturnStuffA", id = UrlParameter.Optional }
);
Now when I enter the URL http://localhost:55302/api/ it all works fine. But when I enter an URL like this: http://localhost:55302/api/SampleId1234 I get the following error "No type was found that matches the controller named 'Sample1234'."
Why does it try to get a controller named Sample1234 and not the defautlt one and use sample1234 as parameter?
Your default route should come last. Route config will look for the configuration from top to bottom and when it finds a match immediately returns invokes that action.
In your case always invoke the first configuration because it matches the api/ configuration.

Categories