c# – 抑制ASP.NET PageMethods文档注释

我有一个ASP.NET WebForm应用程序,它在C#中有一些WebMethod,它是通过jQuery的ajax函数调用的.一切都很好,除了我注意到当我在页面上查看源代码时,我看到的是这样的:

<script type="text/javascript">
    //<![CDATA[
    var PageMethods = function() {
        PageMethods.initializeBase(this);
        this._timeout = 0;
        this._userContext = null;
        this._succeeded = null;
        this._failed = null;
    }
    PageMethods.prototype = {
        _get_path:function() {
            var p = this.get_path();
            if (p) return p;
            else return PageMethods._staticInstance.get_path();},
            CreateNewFranchise:function(name,firstName,lastName,address1,address2,streetSuffixId,city,stateId,county,zip,mainPhoneAreaCode,mainPhoneTypeId,mainPhonePrefix,mainPhoneSuffix,storeCode,storeKey,merchantId,corporateShop,franchiseNumber,succeededCallback, failedCallback, userContext) {
            /// <param name="name" type="String">System.String</param>
            /// <param name="firstName" type="String">System.String</param>
            /// <param name="lastName" type="String">System.String</param>
            /// <param name="address1" type="String">System.String</param>
            /// <param name="address2" type="String">System.String</param>
            /// <param name="streetSuffixId" type="String">System.String</param>
            /// <param name="city" type="String">System.String</param>
            /// <param name="stateId" type="String">System.String</param>
            /// <param name="county" type="String">System.String</param>
            /// <param name="zip" type="String">System.String</param>
            /// <param name="mainPhoneAreaCode" type="String">System.String</param>
            /// <param name="mainPhoneTypeId" type="String">System.String</param>
            /// <param name="mainPhonePrefix" type="String">System.String</param>
            /// <param name="mainPhoneSuffix" type="String">System.String</param>
            /// <param name="storeCode" type="String">System.String</param>
            /// <param name="storeKey" type="String">System.String</param>
            /// <param name="merchantId" type="String">System.String</param>
            /// <param name="corporateShop" type="Boolean">System.Boolean</param>
            /// <param name="franchiseNumber" type="String">System.String</param>
            /// <param name="succeededCallback" type="Function" optional="true" mayBeNull="true"></param>
            /// <param name="failedCallback" type="Function" optional="true" mayBeNull="true"></param>
            /// <param name="userContext" optional="true" mayBeNull="true"></param>
            ...
            ...
            ...

我想知道的是,如果这些///行是必要的,如果没有,是否有办法让ASP.NET压制它们?对我来说,他们看起来只是XML文档标记,这不应该是必需的.在我的C#中有大约8个WebMethod,这些行加起来,如果可能的话我想过滤掉它们.

最佳答案 这些行只是注释,在调试期间为开发人员提供便利.如果设置了web.config中的以下设置之一,则不会生成注释:

>< deployment retail =“false”/>
>< compilation debug =“false”/>

当ScriptManager.ScriptMode属性显式设置为Release时,不会生成注释.

负责PageMethods脚本生成的类是PageClientProxyGenerator.上面的条件在ScriptManager源代码中描述:

public bool IsDebuggingEnabled {
    get {
        // Returns false when:
        // - Deployment mode is set to retail (override all other settings)
        // - ScriptMode is set to Auto or Inherit, and debugging it not enabled in web.config
        // - ScriptMode is set to Release

        if (DeploymentSectionRetail) {
            return false;
        }
        if (ScriptMode == ScriptMode.Auto || ScriptMode == ScriptMode.Inherit) {
            return AppLevelCompilationSection.Debug;
        }
        return (ScriptMode == ScriptMode.Debug);
    }
}
点赞