Search code examples
asp.net-web-api2odataswaggerasp.net-web-api-routingswashbuckle

How to set Swagger page as default landing page for web api 2 project?


I am working on a WEB API 2 Project. I am using Swagger documentation.

I am also using ODATA V4.

I want to set my default page of my web api to swagger, How can I do it?


Solution

  • You can create a redirect, see an example here:
    http://turoapi.azurewebsites.net/

    All I did was create an index.html with the following code:

    <!DOCTYPE html>
    <html>
    <head>
        <title></title>
        <meta charset="utf-8" />
        <meta http-equiv="refresh" content="0; URL='/swagger'" />
    </head>
    <body></body>
    </html>
    

    With that make sure in Web.config

      <system.webServer>
        <handlers>
          <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
          <remove name="OPTIONSVerbHandler" />
          <remove name="TRACEVerbHandler" />
          <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
        </handlers>
      </system.webServer>
    

    ... it should not include this tag.

    <clear/>