This project is read-only.

Combining a Web API into ASP.NET WebPages

Topics: Web Api
Jan 30, 2012 at 3:01 AM

I've combined the files for my service built using the 6th preview of Web API into a site using ASP.NET Razor WebPages.

All works except I get two errors - project still runs fine with the errors but I would like to know why they are there and how to remove them if possible.

Error 39 Type 'ASP.global_asax' is not defined.
Type 'ASP.global_asax' is not defined. C:\Users\Amy Pond\AppData\Local\Temp\Temporary ASP.NET Files\root\03369e29\ff200118\Sources_App_Code\helpers.vbhtml.72cecc2a.vb 721 69

The helpers.vbhtml is a Razor helper class. I don't think this is the prob as it works with no errors without Web API in the mix.

Deleting the temp ASP files doesn't work either.

Feb 2, 2012 at 3:27 AM

No takers?

Feb 2, 2012 at 1:17 PM
Edited Feb 2, 2012 at 1:17 PM

This is a compilation error on your helper, are you referencing global.asax or any webapi code in that helper?
If so, you might be able to solve this by putting your namespace(s) in web.config system.web/pages/namespaces  or system.web.webPages.razor/pages/namespaces ?

Feb 2, 2012 at 9:44 PM

Thanks for the reply SiggiG but no, the helpers don't reference any of those.

Feb 2, 2012 at 9:45 PM

Check to make sure your global.asax is setup right. Not the code, but the markup.

I have it running in razor just fine with no issues so you did something wrong when putting in the webapi into the project.

Feb 4, 2012 at 7:12 AM

Here is the entire gloabl.asax file.

NOTE: the insert code snippet is now working for me...

<%@ Application Language="VB" %>
<%@ Import Namespace="Microsoft.Web.Optimization" %>
<%@ Import Namespace="System.Web.Routing" %>
<%@ Import Namespace="Microsoft.ApplicationServer.Http" %>

<script runat="server">

    Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
        ' Code that runs on application startup
        ' Route config.
        Dim config As New WebApiConfiguration()
        config.ErrorHandlers = Sub(handlers, endpoint, descriptions) handlers.Add(New ErrorHandler())
        config.IncludeExceptionDetail = True

        ' Add service routes.
        RouteTable.Routes.MapServiceRoute(Of Filters)("getFilters")
        RouteTable.Routes.MapServiceRoute(Of Autocomplete)("findTitles")
    End Sub
    Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
        ' Code that runs on application shutdown
    End Sub
    Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
        ' Code that runs when an unhandled error occurs
        Dim hh = 57
    End Sub

    Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
        ' Code that runs when a new session is started
    End Sub

    Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
        ' Code that runs when a session ends.
        ' Note: The Session_End event is raised only when the sessionstate mode
        ' is set to InProc in the Web.config file. If session mode is set to StateServer
        ' or SQLServer, the event is not raised.
    End Sub

Feb 8, 2012 at 1:23 AM

Any more ideas anyone?

Feb 8, 2012 at 1:25 AM

I won't be able to help you without anything short of your project zipped.

Apr 23, 2013 at 4:47 PM
I'm having the same issue when I added a razor helper class. I get 'ASP.global_asax' not defined errors but it still compiles and runs fine as far as I can tell. Please let me know if you ever find a solution. Thanks.