0

I'm trying to configure routes in MVC5, when i tried to refresh web-page withing angular 4 route it gives me

Server Error in '/' Application.
The resource cannot be found.

how can i config mvc routes to accept also angular routes:

  routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

  routes.MapRoute(
      name: "Default",
      url: "{controller}/{action}/{id}",
      defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
  );
6
  • Do you have proper controller class with proper action(with Route attribute) in it? Commented Jan 3, 2019 at 13:13
  • No i don't have Commented Jan 3, 2019 at 14:15
  • You need add a controller class and add appropriate action with route attributes on it in MVC 5 project then it will work Commented Jan 3, 2019 at 14:46
  • try my solution stackoverflow.com/questions/50601424/… Commented Jan 3, 2019 at 17:40
  • @JohnVelasquez your solution will prevent me from navigate to any of mvc5 views such as login\ register page. it will redirect me only to Home\Indx Commented Jan 6, 2019 at 9:25

1 Answer 1

0

Add following rewrite rule to your web.config

<system.webServer>
<rewrite>
<rules>
<rule name="Main Rule" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="/" />
</rule>
</rules>
</rewrite>
</system.webServer>

Hope this help you.

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

1 Comment

it doesn't wrok

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.