asp.net 错误处理

 、从客户端(...)中检测到有潜在危险的 Request.Form 值。(如图)

解决办法:

1、为 c:/windows/temp 文件夹 设置 IIS_Iusers 可读写权限 (可解决部分问题);

2、修改引用程序的程序池 如 是framwork2.0 修改成framwork4.0;

3、<system.web>配置节中添加 requestValidationMode="2.0",eg: <httpRuntime requestValidationMode="2.0"/>。

、System.FormatException: 输入字符串的格式不正确。 

错误源:int.Parse(context.Request["id"])

原因:网站发布context.Request["id"] 的值是一条guid值,这种格式转换不行。

解决办法:强转 Convert.ToInt32(context.Request["id"]);

三、获取img标签的路径

     /// <summary>
        /// Function:获取信息中的url src
        /// </summary>
        /// <param name="message">数据源</param>
        /// <returns></returns>
        public List<string> GetImgUrl(string message)
        {
            List<string> result = new List<string>();//定义一个泛型字符类
            if (!string.IsNullOrEmpty(message) && message.ToLower().Contains("src"))
            {
                Regex reg = new Regex(@"<img[^<>]*?src[s	
]*=[s	
]*[""']?[s	
]*(?<imgUrl>[^s	
""'<>]*)[^<>]*?/?[s	
]*>", RegexOptions.IgnoreCase);
                MatchCollection mc = reg.Matches(message); //设定要查找的字符串
                foreach (Match m in mc)
                {
                    result.Add(m.Groups["imgUrl"].Value);
                }
            }
            return result;
        }

三、可编辑的下拉框  select

<!--zhaoyang 2014.12.12-->
<table width="150" style="position: relative;">
    <tr>
        <td>
            <select style=" 150px;" name="cmbno" id="cmbno">
                <option value="" selected="selected">请选择</option>
                <option value='F000000001'>F000000001</option>
                <option value='F000000003'>F000000003</option>
            </select>
            <input type="text" value="请选择" name="cmbnoText" id="cmbnoText" style="border: 0;
                background: #fff;  127px; position: absolute; left: 5px; top: 4px;" />
        </td>
    </tr>
</table>
View Code

四、URL编码 ‘ ’ 被转换成 '+':

System.Web.HttpUtility.UrlEncode(“这是段   测试文字”).Replace("+", "%20");

五、Windows服务 Directory.CreateDirectory 访问被拒绝

改成以下方式:

dir = Directory.CreateDirectory(path);
dir.Create();
原文地址:https://www.cnblogs.com/kongxp/p/4140224.html