VS2010/VS2013中ashx代码折叠的问题

Tools->Options->TextEditor->File Extension

Add ashx Microsoft Visual C#

Apply

OK

重启VS就可以了,效果如下图所示

代码折叠是可以了,但是有一点不舒服的是,第一行<%@这里会出现红线,不影响程序运行,但是看着不舒服(强迫症犯了)。

 

.ashx文件还有另外一个问题:.ashx文件中的代码不会被编译到.dll文件中。

要解决这个问题,可以把.ashx文件中的cs代码分离出来,也就是把.ashx文件中除了第一行之外的所有代码剪切掉,在App_Code中创建一个class文件,把刚才剪切的代码全部覆盖到新建的class文件中,假设我们创建的class文件的名称是 Test.cs,修改一下.ashx文件的第一行代码,加上 CodeBehind="Test.cs",.ashx文件的所有代码如下:

<%@ WebHandler Language="C#" class="Handler" CodeBehind="Test.cs" %>

Test.cs的所有代码如下:

using System;
using System.Web;

public class Handler : IHttpHandler
{

    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "text/plain";
        context.Response.Write("Hello World");
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }

}

这样,代码折叠解决了,发布WEB程序的时候,.ashx相关的cs代码也会被编译到App_Code.dll文件中。

只是创建文件的时候需要手动去修改一下,稍微有点麻烦。

 

转载于:https://www.cnblogs.com/oukunqing/p/5935539.html

var editor; var action = $.queryString("action"); var Pid = $.queryString("id"); $(function () { //设置返回列表的href, location_prior的href在后台打开当前记录信息时赋值。 // $("#location_back").attr("href", $("#location_prior").attr("href")); //用户获取出来,获取本部门用户。 //获取本部门的权限, $.ajax({ type: "POST", url: "../services/Dtry.ashx", headers: { "Authorization": "0772A4AA051DDEBB393DC164B19A32E57C4FEEAB27A77820" }, data: { action: "names", id: Pid }, success: function (msg) { $.each(msg.ds, function (index, item) { if (item.pid == -1) { $('#qx').append('<div><ul><li> <input id="a' + item.id + '" type="checkbox" name="select_checkbox" onclick="chk_changed();" value="' + item.id + '" /><a class="sz" href="javascript:onClick=show(' + item.id + ')">' + item.name + '</a></li></ul><ul id="' + item.id + '"> </ul></div>'); } else { $('#' + item.pid).append('<li class="sc"> <input id="a' + item.id + '" type="checkbox" name="select_checkbox" onclick="chk_changed(this);" value="' + item.id + '"/><a class="zt" href="javascript:onClick=show(' + item.id + ')">' + item.name + '<br/><ul class="cc" style="display:none" id="' + item.id + '"> </ul></li>') } }) $('#typeid').val(Pid); } }); $('#user_nickname').on('change', getQ); //初始化表单验证 $("#form1").initValidform(); $(".rule-single-checkbox").ruleSingleCheckbox(); $(".rule-single-select").ruleSingleSelect(); // var result = ""; }); function chk_changed(that) { var th = $(that); if (th.is(':checked')) { console.log('已选中'); } else { console.log('未选中'); } th.next('a').find('input').attr("checked", "true"); th.parent().parent().siblings().find('input').attr("checked", "true"); th.parent().parent().parent().siblings().attr("checked", "true"); var result = ""; $("input[name='select_checkbox']:checked").each(function () { result += $(this).val() + ','; }); if (result != "") { result = result.substring(0, result.lastIndexOf(',')); } $("#typename").val(result); } function show(d1) { if (document.getElementById(d1).style.display == 'none') { document.getElementById(d1).style.display = 'block'; //触动的层如果处于隐藏状态,即显示 } else { document.getElementById(d1).style.display = 'none'; //触动的层如果处于显示状态,即隐藏 } } var getQ = function () { var userid = $('#user_nickname').val(); if (userid == null || userid == undefined) { return false; } else { $.ajax({ type: "POST", url: "../services/Dtry.ashx", headers: { "Authorization": "0772A4AA051DDEBB393DC164B19A32E57C4FEEAB27A77820" }, data: { action: "getQ", id: userid }, success: function (msg) { $.each(msg.ds, function (index, item) { $('#a' + item.typeid).attr("checked", true); }) var result = ""; $("input[name='select_checkbox']:checked").each(function () { result += $(this).val() + ','; }); if (result != "") { result = result.substring(0, result.lastIndexOf(',')); } $("#typename").val(result); } }); } } 详细翻译代码内容
03-11
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值