12

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:

http://localhost/#access_token=fzgSLjF4W0QAHlhsNFZI...

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.

Suggestions?

smoore4
  • 4,520
  • 3
  • 36
  • 55

4 Answers4

8

See this answer

Use the Visual Studio "Web Deploy" publish method.

Set "Site name" to localhost/api instead of localhost

Josh
  • 2,142
  • 2
  • 23
  • 20
3

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}"
smoore4
  • 4,520
  • 3
  • 36
  • 55
1

Have you tried adding virtual directory in your IIS website?
I have my API as separate project and I can refer to it by using www.your-web-site/API-subfolder

To do it go to your IIS -> context menu on your website. Then:
enter image description here
And add alias (subfolder-name) and Physical path to your API project.
It should work

Lokki
  • 372
  • 1
  • 6
  • 20
  • I tried that but got an error saying that it needed to be a web application. – smoore4 Aug 31 '15 at 14:39
  • Try creating API web application, Include your WebApi project in there and then refer virtual directory to your API web application. – Lokki Aug 31 '15 at 14:59
  • @Lokki..i am trying to host my web api as virtual directory. I am able to see directory listing but when i am trying to hit the controller i am not able to do that.Any idea what i am doing wrong? – Developer Nov 28 '20 at 19:06
1

I went thru hell with this and here is what I do to fix that issue:

When on Content View just click on the subfolder and select "Convert To Application". Thats it.

Then just click on the newly created Application and hit browse, it will show you the default page of the Web API Project.

LordXmen2K
  • 29
  • 4