Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

I have an ASP.NET MVC login page and on login button click, it is redirecting to another page which is connected with angular, Once I logged in, the url redirecting me to something like below

http://localhost:5083/Home#/home

I need to remove the ASP MVC controller name ("Home") from the Url, how can i do that?

enter image description here

Angular Routing Config enter image description here

ASP.NET MVC Routing Config enter image description here

Login page location - AccountContrller->Index.cshtml and on login button click it moved to HomeController -->index.cshtml

share|improve this question
1  
Is Login action in HomeController? Could you please provide the angular route config as well? – Developer Aug 18 at 4:50
    
@Developer please refer the updated question.. Thanks and regards – Aslam Jiffry Aug 18 at 5:15
1  
might be worth your while to check this out, seeing that you are trying to mix mvc and angular c-sharpcorner.com/UploadFile/cd7c2e/… – R4nc1d Aug 18 at 5:21
1  
@AslamJiffry- In that case, I think your MVC default route is not pointing to HomeController. Should work as you expect if you point MVC default route to Home and Index. This is what happens: - request comes to localhost:5083 - MVC resolves the default route - request reached Home controller -. Index action - where it returns the view which bootstraps angularjs - works according to angularjs route – Developer Aug 18 at 5:57
2  
For Login , give specific route-> localhost:5083/Login and let the default route be Home. When user navigates to localhost:5083 then check whether the user is authroized, and if not redirect to Login. – Developer Aug 18 at 6:53
up vote 1 down vote accepted

Update your MVC default route so that it points to Home controller and action as Index - so when request comes as localhost:5083, mvc will resolve the controller as Home and action as Index, which will inturn bootstrap the angularjs routing.

share|improve this answer

In the page provided by MVC (Home/Index.cshtml), if you set the Base Href to /Home then angular2 will be able to route everything relative to /Home and then you don't need to remove /Home from the URL, so at the top of Index.cshtml add:

<head>
<base href="/Home/"
share|improve this answer
    
where should I include this? within the partial view or index.cshtml which include <ng-view> ?.. I included that in Home/Index.cshtml, But as a result routing system didn't work.. thanks & regards – Aslam Jiffry Aug 18 at 6:54
1  
It should go in the index.cshtml, but this won't work if you use default route of Home as you have discussed in the comments in the original post. Here is an article discussing base href: verdantrefuge.com/writing/2013/… – Slicc Aug 18 at 6:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.