4

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

12
  • 1
    Is Login action in HomeController? Could you please provide the angular route config as well? Commented Aug 18, 2016 at 4:50
  • @Developer please refer the updated question.. Thanks and regards Commented Aug 18, 2016 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/… Commented Aug 18, 2016 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 Commented Aug 18, 2016 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. Commented Aug 18, 2016 at 6:53

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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/"

2 Comments

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
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/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.