The service cannot be activated because it does not support ASP.NET compatibility

本文讨论了在ASP.NET环境下创建Service时遇到的异常问题,并提供了通过修改web.config和为Service添加特定属性来解决的方法。对于拥有多个Service的情况,文章还提出了更优化的解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

刚刚在ASP.NET创建一个Service,在运行时,它即显示异常:

 

The service cannot be activated because it does not support ASP.NET compatibility. ASP.NET compatibility is enabled for this application. Turn off ASP.NET compatibility mode in the web.config or add the AspNetCompatibilityRequirements attribute to the service type with RequirementsMode setting as 'Allowed' or 'Required'.

解决方法,你需要为你的Service添加一个属性:


第#11行代码:

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]


上面的解决方法,它只是为单独某一个Service。如果你有多个Service时,那需要在每一个Service均需要添加上面的属性。
有一个更好的方法,就是修改web.config:


 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值