0

I have a .NET Core website which is published successfully and works great under 2 scenarios:

  1. In debug mode
  2. When hosted in IIS as a new website.

However, hosting on IIS as a new website leads me to having to specify a new port to be used and access it by it (localhost:5000).

However i would like to address it as the domain itself like localhost/mywebsite. From my understanding this could be done by using the default web site, or by creating a new website with port 80 and disabling the Default Web Site. However i cannot disable the Default Web Site.

When i try to add my website to the Default Web Site, i have numerous errors because ultimately, the routing is not good. For example, the main page works (for example localhost/mywebsite) but when i click on a button to get to the login page, im routed to localhost/login and not localhost/mywebsite/login.

Extra information:

Published folder: After publishing, i have 2 folders: wwwroot, runtimes. Other than that i have all the config files and binaries.

web.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <location path="." inheritInChildApplications="false">
    <system.webServer>
      <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
      </handlers>
      <aspNetCore processPath="dotnet" arguments=".\mywebsite.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
    </system.webServer>
  </location>
</configuration>

Resources are located in project's wwwroot. Resources included are JQuery and images. These also do not work when used as application under Default Web Site.

example post method requested by first comment:

<form method="post" enctype="multipart/form-data" action="/Login/Login">
    <table style="border: none">
        <tr>
            <td>
                Username:
            </td>
            <td>
                <input type="text" name="username" required />
            </td>
        </tr>
    </table>
    <input type="submit" value="Log-In" />
</form>
Tomer Something
  • 770
  • 1
  • 10
  • 24
  • Can you share your html code for the links? Also, do you want to be: localhost/mywebsite or localhost which will host your website? – Shaul Zuarets Jan 02 '19 at 08:08
  • @ShaulZuarets: first question answered with the last edit. Second question: localhost/mywebsite – Tomer Something Jan 02 '19 at 08:13
  • Something I don't understand. Even when you host outside of IIS, using Kestrel directly for instance, you can set a custom base path so make it listen on a different path. When in Configure(...) you call app.UsePathBase("/mycustompath") you should be able to contact your controller via http://localhost:5000/mycustompaht/controllerName/controllerAction And this is more or less what IIS does, it sets a path base. Can you try setting that path, launch it outside of IIS, and tell us if your action login is working fine? If not, your issue can be reproduce outside of IIS. – Daboul Jan 02 '19 at 08:41
  • Moreover, I have removed the Default web site from IIS, it is working fine. Maybe you need to have another web site defined prior of doing it? – Daboul Jan 02 '19 at 08:41
  • @Daboul firstly i apologize for my ignorance. Web design is not my domain. I have declared a base path, which is usable, but after i click on Login button im directed to localhost:5000/login without my base path. Moreover, as i said i do not wish to state the port, i want to use it like any other web where you just enter the domain name and the website name.. – Tomer Something Jan 02 '19 at 08:56
  • @TomerSomething of course, you don't need to apologize. the thing is, as the html code has been downloaded from a path with a particular path base, let's say http://localhost/mywebsite/test.html, it should know that the action needs to reference an address using the same path base, http://localhost/mywebsite/login. I think the way you have written the HTML might be the issue here. In action="/Login/Login" could you remove the first '/' ? – Daboul Jan 02 '19 at 09:07
  • Can you check with a piece of javscript what is the base url of your website? Simple method suggested here: https://stackoverflow.com/questions/25203124/how-to-get-base-url-with-jquery-or-javascript – Daboul Jan 02 '19 at 09:11
  • Do you *need* to keep using the default web site, or do you just want to replace it and make sure that you can use your ASP.NET Core app without a port? – poke Jan 02 '19 at 13:50
  • How did you publish your project to IIS? If issue still eixsts, try to share us a demo which could reproduce your issue. – Edward Jan 03 '19 at 03:23
  • "From my understanding this could be done by using the default web site, or by creating a new website with port 80 and disabling the Default Web Site." Please think out of the box and learn what is reverse proxy, https://learn.microsoft.com/en-us/iis/extensions/url-rewrite-module/reverse-proxy-with-url-rewrite-v2-and-application-request-routing – Lex Li Mar 22 '20 at 05:50

0 Answers0