문제

I have an ASP.NET WebForm application that has some WebMethod's in C# that is being called through jQuery's ajax functions. Everything is working fine, except I notice that when I view source on the page, I'm seeing something like this:

<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>
            ...
            ...
            ...

What I am wondering is if these /// lines are necessary and if not, is there a way to make ASP.NET suppress them? To me, they look like they are just XML documentation markups, which shouldn't be necessary. Having about 8 WebMethod's in my C#, these lines add up and I'd like to filter them out if possible.

도움이 되었습니까?

해결책

These lines are just comments and made for a developer convenience during debug. Comments are not generated if one of the following settings in web.config are set:

  • <deployment retail="false" />
  • <compilation debug="false" />

Plus comments are not generated when ScriptManager.ScriptMode property is explicitly set to Release.

The class which is responsible for PageMethods script generation is PageClientProxyGenerator. And conditions above are described in ScriptManager source code:

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);
    }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top