【问题标题】:Vb.Net Web application with webform page add webapi 2.2带有Web表单页面的Vb.Net Web应用程序添加Web api 2.2
【发布时间】:2019-09-13 08:50:14
【问题描述】:
  • 我在 Vb.Net 中有 Web 应用程序项目
    • 我想将 web api 添加到我的项目中
    • 带有 .Net 4.7.2 的 Visual Studio 2019

但是当我运行应用程序时它会抛出一个错误:

Line 27: Line 28: ' 在应用程序启动时运行的代码 第 29 行:GlobalConfiguration.Configuration(AddressOf AppStart.WebApiConfig.Register) 第 30 行:
''GlobalConfiguration.Configuration(注册)

输出:

Microsoft (R) Visual Basic 编译器版本 14.8.3761 for Visual Basic 2012 版权所有 (c) Microsoft Corporation。保留所有权利。

此编译器作为 Microsoft (R) .NET Framework 的一部分提供, 但仅支持最高 Visual Basic 2012 的语言版本,即 不再是最新版本。对于支持较新的编译器 Visual Basic 编程语言的版本,请参见 http://go.microsoft.com/fwlink/?LinkID=533241

C:project\webapp\global.asax(29) : 错误 BC30545: 必须访问属性 分配给属性或使用它的值。

    GlobalConfiguration.Configuration(AddressOf AppStart.WebApiConfig.Register)

我已经从 nuget 下载了所有的包:

  • Microsoft.asp.net.wabapi
  • Microsoft.asp.net.wabapi.clinet
  • Microsoft.asp.net.wabapi.Core
  • Microsoft.asp.net.wabapi.selfHost

global.asax

Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)

        ' Code that runs on application startup
        GlobalConfiguration.Configuration(AddressOf AppStart.WebApiConfig.Register)

End Sub

webapiconfig 类

Imports System.Web.Http

Namespace AppStart

    Public Class WebApiConfig

        Public Shared Sub Register(configuration As HttpConfiguration)

            '// Web API routes
            configuration.MapHttpAttributeRoutes()

            configuration.
                          Routes.
                          MapHttpRoute(
                                      "API Default",
                                      "webapi/{controller}/{id}",
                                       New With {Key .id = RouteParameter.Optional}
                          )
        End Sub

    End Class

End Namespace

网络配置

<system.webServer>
      <validation validateIntegratedModeConfiguration="false" />
      <handlers>

        <!--webapi-->
        <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" />
        <!-- end web api -->

</handlers>
<system.webServer>

提前感谢您的帮助

【问题讨论】:

    标签: .net vb.net api webforms


    【解决方案1】:

    我唯一做的就是更新web.config

    <?xml version="1.0" encoding="utf-8"?>
    <configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
    

    通过删除 xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0"

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

    看起来这条线导致了这个错误:

    Microsoft (R) Visual Basic Compiler version 14.8.3761 
    for Visual Basic 2012 Copyright (c) Microsoft Corporation. 
    All rights reserved.
    which is no longer the latest version. 
    For compilers that support newer versions of the Visual Basic programming language, see 
    

    【讨论】:

      猜你喜欢
      • 2013-12-30
      • 1970-01-01
      • 1970-01-01
      • 2016-10-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-06
      相关资源
      最近更新 更多