smoore4 smoore4 - 3 years ago 304
ASP.NET (C#) Question

Publish WebApi to Subfolder

I have an out-of-the-box Visual Studio 2013 SPA using WebApi. I added Twitter authentication to Startup.Auth.cs and all of it works just fine when I publish to the root of an IIS web site or when I debug in VS with localhost.

What I can't figure out is how to publish the project to a subfolder like this:

enter image description here

In other words, http://localhost/api

The site itself works. It is the ReturnUrl from Twitter that always redirects to http://localhost/# It includes the correct access_token but in this format:


If I manually type in "api/" before #access_token it opens the default Index page and is authenticated via Twitter. I have tweaked every setting on the Twitter side, javascript, and .cs. I just can't find a solution other than Publish to a root web site. I would like to publish to a subfolder application.


Answer Source

After going through each folder, I noticed one folder that I did not check - Providers. And in there is a class called ApplicationOAuthProviders.cs. Once I changed values in that file, social logins started to redirect correctly.

There are a number of changes that need to change to publish to a subfolder; they are:

  • ApplicationOAuthProvider: context.Request.Uri, "/YourSubfolder/"
  • app.datamodel.js: self.userInfoUrl = "YourSubfolder/me"; (remove first slash)
  • app.viewmodel.js : window.location = "/YourSubfolder/Account/Authorize?client_id=web&response_type=token&state=" + encodeURIComponent(window.location.hash);
  • WebApiConfig.cs: routeTemplate: "YourSubfolder/{controller}/{id}"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download