locked
Access .aspx page RRS feed

  • Question

  • User582566331 posted

    How to run the code behind when we create an .aspx page in webapi application. Its showing blank page. not executing the code.

    Tuesday, February 26, 2019 10:01 AM

All replies

  • User36583972 posted


    Hi sweetyPaul,

    How to run the code behind when we create an .aspx page in webapi application. Its showing blank page. not executing the code.

    de.

    I can add a .aspx page in webapi and set as start page. I can show the page and execute some code.

    If you want to add Web API to a traditional ASP.NET Web Forms application. You can refer the following tutorial.

    Using Web API with ASP.NET Web Forms
    https://docs.microsoft.com/en-us/aspnet/web-api/overview/getting-started-with-aspnet-web-api/using-web-api-with-aspnet-web-forms

    Best Regards,

    Yong Lu

    Wednesday, February 27, 2019 3:15 AM
  • User582566331 posted

    for me its not working.my webapi.config code is as follows

    config.EnableCors()
    ' Web API routes
    config.MapHttpAttributeRoutes()

    config.Routes.MapHttpRoute(
    name:="DefaultApi",
    routeTemplate:="api/{controller}/{id}",
    defaults:=New With {.id = RouteParameter.Optional}
    )

    RouteTable.Routes.MapHttpRoute(
    name:="DefaultApi1",
    routeTemplate:="api/{controller}/{id}",
    defaults:=New With {.id = RouteParameter.Optional}
    ).RouteHandler = New SessionHttpControllerRouteHandler()

    Dim httpControllerRouteHandler = GetType(HttpControllerRouteHandler).GetField("_instance", System.Reflection.BindingFlags.Static Or System.Reflection.BindingFlags.NonPublic)

    If httpControllerRouteHandler IsNot Nothing Then
    httpControllerRouteHandler.SetValue(Nothing, New Lazy(Of HttpControllerRouteHandler)(Function() New SessionHttpControllerRouteHandler(), True))
    End If

    config.Routes.MapHttpRoute("OfficeApi", "api/{controller}/{action}/{id1}/{Id2}")

    config.Routes.MapHttpRoute(
    name:="DefaultApi2",
    routeTemplate:="api/{controller}/{action}/{id}",
    defaults:=New With {.id = RouteParameter.Optional}
    )

    config.Routes.MapHttpRoute("DefaultApiWithAction", "Api/{controller}/{action}")

    Wednesday, February 27, 2019 4:11 AM
  • User36583972 posted


    Hi sweetyPaul,

    for me its not working.my webapi.config code is as follows

    Unfortunately, we cannot reproduce your issue.

    I have created a new Web API 2 and add a .aspx page in webapi and set as start page. I still can show the page and execute some code.

    I suggest you can create a new project and test.

    Note: I use the Visual Studio 2017.

    Besides, we do not recommend that you add a .aspx page in webapi.

    Best Regards

    Yong Lu

    Thursday, February 28, 2019 6:53 AM