提问人:sam it 提问时间:9/13/2019 最后编辑:theducksam it 更新时间:5/30/2020 访问量:831
Vb.Net Web 应用程序与 Web 表单页面添加 WebAPI 2.2
Vb.Net Web application with webform page add webapi 2.2
问:
- 我在 Vb.Net 有 Web 应用程序项目
- 我想将 Web API 添加到我的项目中
- 带有 .Net 4.7.2 的 Visual Studio 2019
但是当我运行应用程序时,它会抛出一个错误:
第 27 行: 第 28 行: ' 在应用程序启动时运行的代码 第 29 行:GlobalConfiguration.Configuration(AddressOf AppStart.WebApiConfig.Register) 第 30 行:
''GlobalConfiguration.Configuration(Register)
输出:
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
全球.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>
提前感谢您的任何帮助
答:
0赞
sam it
5/30/2020
#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
评论