2

I am new with Web Api and using n-tier architecture. I have a simple application with AngularJs as javascript framework and using Web Api as RESTFul service. I also have Data Access Layer, Business Logic Layer and a separate layer for Model.Html pages are included in same project containing Api, in Pages folder. This is my project structure: enter image description here

I am trying to host the project on Local IIS. I have changed the servers option from properties of FirstApp.Web to local IIS. Html pages are being displayed fine. The page contains simple login form. Using Angularjs service I am calling the Web Api which is under Controllers folder.

this.authenticate = function (obj) {
        return $http.post('/api/Employee/Validate/', obj, {});
    }

But it is throwing enter image description here

Help me to figure out how to host the whole application on local IIS.

4
  • Does the application work when you debug in Visual Studio? Commented Feb 25, 2016 at 0:50
  • application is working fine with IIS Express but not on Local IIS. Commented Feb 25, 2016 at 0:52
  • Could you post the URL which runs on Local IIS? Commented Feb 25, 2016 at 0:53
  • It is : localhost/FirstApp.Web/Pages/index.html Commented Feb 25, 2016 at 0:56

1 Answer 1

1

It happens if you do not host the application at root level - http://localhost/Pages/Index.html.

In my saturation, I use ASP.Net MVC _layout.cshtml, so I get the site's URL using @Url.Content("~"), and append it at the front of every Angular's requested URL.

// This script tags is placed inside _layout.cshtml
<script type="text/javascript">        
    window.MyApp = {
        rootPath: '@Url.Content("~")'
    };
</script>

Usage

this.authenticate = function (obj) {
   return $http.post(window.MyApp.rootPath + 'api/Employee/Validate/', obj, {});
}
Sign up to request clarification or add additional context in comments.

2 Comments

But I am not using Razor view. It is simple html page. Any work around for this?
If regular html page, you will need to place the above script inside index.html, and manually update rootPath like this window.MyApp = { rootPath: '/FirstApp.Web/' };

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.