0

I just created a basic Web Controller in my project. I hit debug and try to browse to /api/duedate and I get a 404. I am new to controllers and have been looking at every tutorial I can find. None of them say I need to add anything more to get this to work.

 Imports System.Net
Imports System.Web.Http

Public Class DueDateController
    Inherits ApiController

    ' GET api/duedate
    Public Function GetValues() As IEnumerable(Of String)
        Return New String() {"value1", "value2"}
    End Function

    ' GET api/duedate/5
    Public Function GetValue(ByVal id As Integer) As String
        Return "value"
    End Function

    ' POST api/duedate
    Public Sub PostValue(<FromBody()> ByVal value As String)

    End Sub

    ' PUT api/duedate/5
    Public Sub PutValue(ByVal id As Integer, <FromBody()> ByVal value As String)

    End Sub

    ' DELETE api/duedate/5
    Public Sub DeleteValue(ByVal id As Integer)

    End Sub
End Class

My web.config looks like this:

<?xml version="1.0" encoding="utf-8"?>
<configuration>

  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
    <add key="webPages:Version" value="2.0"/>
  </appSettings>
  <system.web>
    <compilation debug="true" strict="false" explicit="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
  </system.web>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <protocolMapping>
        <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>    
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
    <!--
        To browse web app root directory during debugging, set the value below to true.
        Set to false before deployment to avoid disclosing web app folder information.
      -->
    <directoryBrowse enabled="true" />
  <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>

</configuration>

2 Answers 2

1

I believe you need to add a route.

Routing in VB

If you read the last comment in this thread it should show you how to add routing to your app.

Sign up to request clarification or add additional context in comments.

5 Comments

I have MapPageRoute available not RouteTable.Routes.MapHttpRoute
Do you have the same imports as he does? Are you maybe missing a reference?
I confirmed that I have all the references and imports he does. I've even tried adding additional ones. No luck
Alright, Intellisense is messed up. It's there just won't recommend it.
Ctrl + Shift + R will refresh the Intellisense Cache.
0

To help anyone else out and to simplify having to read through that long post. You need to create and modify your global.asax file to include this:

Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
    RouteTable.Routes.MapHttpRoute("WebApi1",
                                  "api/{controller}/{id}",
                                  defaults:=New With {.id = System.Web.Http.RouteParameter.Optional})
End Sub

Comments

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.