在配置文件中禁用ASP.net Rest服务

编程入门 行业动态 更新时间:2024-10-10 03:25:09
本文介绍了在配置文件中禁用ASP Rest服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

大家好, 我有一个使用两个WCF REST服务的asp网站.这些其余服务之一仅在应用程序在QA环境中运行时才有效.因此,我正在寻找一种在发布到生产环境时禁用此功能的方法. 如何禁用配置文件中IIS中托管的REST wcf? 注意:如果我从网络配置中删除了服务配置部分,它将使用默认配置!因此该服务仍然有效! 有什么主意吗? 谢谢.

Hi Guys, I have a asp web site which is using two WCF REST services. one of these rest services is just valid when the application is working in the QA env. so I am looking to find a way to disable this one when publishing to production. How can I disable a REST wcf which is hosted in IIS in config file? note: if I remove the service configuration part from web config it will use the default configuration! So the service still working! any idea? Thank you.

推荐答案

如评论中所述,最好的前进方法是为QA& A定义Web.Config文件.生产- Web.Config转换 以下MSDN Blog条目对此进行了解释: ASP.NET Web项目:web.debug.config& web.release.config [ ^ ] web.config 这是开发人员应在本地使用的配置文件.理想情况下,您应该对此进行标准化.例如,您可以将localhost用于数据库字符串,而不要使用localhost.您应该努力使它在开发机器上正常工作. web.debug.config 这是在将应用程序发布到开发暂存环境时应用的转换.这将对目标环境所需的web.config进行更改. web.release.config 这是在将应用程序发布到生产"环境时应用的转换.显然,根据您的应用程序/团队,您必须小心使用密码. 更多详细信息: MSDN:如何:在部署Web应用程序项目时转换Web.config [ ^ ] MSDN:转换Web.Config文件以进行部署 [ ^ ] 在ASP.NET中支持开发和发布web.config [ ^ ] As mentioned in comments, best way to move ahead will be to have defined Web.Config files for QA & Production - Web.Config Transformation Following MSDN Blog entry explains it: ASP.NET Web Projects: web.debug.config & web.release.config[^] web.config This is the config file which developers should use locally. Ideally you should get this to be standardized. For instance you could use localhost for DB strings, and what not. You should strive for this to work on dev machines without changes. web.debug.config This is the transform that is applied when you publish your application to the development staging environment. This would make changes to the web.config which are required for the target environment. web.release.config This is the transform that is applied when you publish your application to the "production" environment. Obviously you''ll have to be careful with passwords depending on your application/team. More details: MSDN: How to: Transform Web.config When Deploying a Web Application Project[^] MSDN: Transforming a Web.Config File for Deployment[^] Supporting Development and Release web.config in ASP.NET[^]

对于那些有相同问题的人, 我已经这样定义了我的svc文件: For those who have the same problem, I had defined my svc file like this: <![CDATA[<%@ ServiceHost Language="C#" Debug="true" Service="ServiceName" CodeBehind="~/App_Code/ServiceName.cs" Factory="System.ServiceModel.Activation.WebServiceHostFactory" %>]]>

通过这样做,即使我的web.config中没有任何配置,似乎IIS(或...)也激活了我的服务!因此,我从svc文件中删除了Factory ="..".通过这样做,我必须在配置文件中定义它,否则它将不起作用,因此我在配置文件中添加了以下额外的行:

by doing this, It seems IIS (or ...) activates my service even if I don''t have any configuration in my web.config! So the I removed the Factory=".." from the svc file. by doing this, I have to define it in the config file otherwise it will not work, so I added this extra lines to my config files:

<servicehostingenvironment aspnetcompatibilityenabled="true"> <serviceactivations> <add relativeaddress="ServiceName.svc" service="ServiceName" factory="System.ServiceModel.Activation.WebServiceHostFactory" /> </serviceactivations> </servicehostingenvironment>

现在一切都很好,每当我要禁用此服务时,都可以在配置文件中删除相关设置! 谢谢.

Now every thing is fine, when ever I want to disable this service, I can remove the related settings in the config file! Thank you.

更多推荐

在配置文件中禁用ASP.net Rest服务

本文发布于:2023-11-07 15:30:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1566825.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:配置文件   ASP   Rest   net

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!