c#(asp.net/core)杂谈笔记
1.js解析json格式的时间
//转换json格式时间的方法 如Date(1340239979000)转换为正常function ConvertJSONDateToJSDateObject(JSONDateString) {var date = new Date(parseInt(JSONDateString.replace("/Date(", "").replace(")/", ""), 10));var year = date.getFullYear();var month = date.getMonth + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();var hour = date.getHours();var minute = date.getMinutes();var second = date.getSeconds();var datastr = year + "-" + month + "-" + currentDate + " " + hour + ":" + minute + ":" + second;return datastr;}
2.查询父分类下的所有子分类(sql)。
with a as (select * from TbRegion where RegionUid='1'union allselect s.* from TbRegion as s , a where s.ParRegionUid=a.RegionUid ---这里查的a表是那个表啊? ) select * from a
3.ajax获取session
using System.Web.SessionState; //添加此引用 public class roadshow_demo : IHttpHandler, IReadOnlySessionState //继承IReadOnlySessionState接口 { public void ProcessRequest (HttpContext context) {context.Response.ContentType = "text/plain";
4.获取别人网页上自己想要的链接地址
using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq;using System.Net; using System.IO; using System.Text; using System.Text.RegularExpressions; using HtmlAgilityPack;namespace asp.net技术点测试 {public partial class _Default : System.Web.UI.Page{//HtmlAgilityPack.dll//http://blog.cnfol.com/jldgoldprotected string aa;protected void Page_Load(object sender, EventArgs e){//HttpWebRequest httpWebRequest = WebRequest.Create(@"http://blog.cnfol.com/jldgold/list") as HttpWebRequest;//HttpWebResponse httpWebResponse = httpWebRequest.GetResponse() as HttpWebResponse;//Stream stream = httpWebResponse.GetResponseStream();//StreamReader reader = new StreamReader(stream, Encoding.UTF8);//string s = reader.ReadToEnd();//reader.Close();//stream.Close();//httpWebResponse.Close();//HtmlDocument htmlDoc = new HtmlDocument();//htmlDoc.LoadHtml(s);//HtmlNodeCollection anchors = htmlDoc.DocumentNode.SelectNodes(@"//a");//foreach (HtmlNode anchor in anchors)//{// Regex reg = new Regex("景良东:");// if (reg.Matches(anchor.InnerHtml).Count == 0)// {// }// else// {// Response.Write(anchor.OuterHtml + "<br/>");// }//}//Response.End();Response.Write(GainLink("http://blog.cnfol.com/jldgold/list","景良东:"));Response.End();}/// <summary>/// 获取网页上自己想要的链接/// </summary>/// <param name="link">获取网页上的链接的网页地址</param>/// <param name="regexstr">正则匹配自己想要的链接所共有包含的内容</param>/// <returns>返回链接集合</returns>public string GainLink(string link, string regexstr){String str="";HttpWebRequest httpWebRequest = WebRequest.Create(link) as HttpWebRequest;HttpWebResponse httpWebResponse = httpWebRequest.GetResponse() as HttpWebResponse;Stream stream = httpWebResponse.GetResponseStream();StreamReader reader = new StreamReader(stream, Encoding.UTF8);string s = reader.ReadToEnd();reader.Close();stream.Close();httpWebResponse.Close();HtmlDocument htmlDoc = new HtmlDocument();htmlDoc.LoadHtml(s);HtmlNodeCollection anchors = htmlDoc.DocumentNode.SelectNodes(@"//a");foreach (HtmlNode anchor in anchors){Regex reg = new Regex(regexstr);if (reg.Matches(anchor.InnerHtml).Count == 0){}else{str += anchor.OuterHtml+"</br>";}}return str;}} }
5.ckedit、ckfinder的使用。。
<html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"><title>无标题页</title><script src="ckeditor/ckeditor.js" type="text/javascript"></script><script src="ckfinder/ckfinder.js" type="text/javascript"></script> </head> <body><form id="form1" runat="server"><div><asp:TextBox ID="txtcontent" runat="server" TextMode="MultiLine" Height="550px" Width="100%"></asp:TextBox></div><script type="text/javascript">var editor = CKEDITOR.replace('<%= txtcontent.ClientID %>');CKFinder.setupCKEditor(editor, '../ckfinder/');</script></form> </body> </html>
6.图片延时加载
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="图片延时加载._Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>Lazy Load Enabled</title><script src="Scripts/jquery-1.4.2.min.js" type="text/javascript"></script></head><body><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /> <!--备注,必须有滚滚动条出现,才能有延时加载效果。所以这里加了一对换行符,为了获得滚动条--><img lazyload="img/bmw_m1_hood.jpg?1277878639" /><br /><img lazyload="img/bmw_m1_side.jpg?1277878639" /><br /><img lazyload="img/viper_1.jpg?1277878639" /><br /><img lazyload="img/viper_corner.jpg?1277878639" /><br /><img lazyload="img/bmw_m3_gt.jpg?1277878639" /><br /><img lazyload="img/corvette_pitstop.jpg?1277878639" /><br /><script type="text/javascript" src="Scripts/LazeLoad.js"></script> <!--这里是需要下载添加的js--><script type="text/javascript"> lazyLoad.Run();</script></body> </html>
7.无刷新图片预览、上传
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>图片预览效果</title> <script src="js/CJL.0.1.min.js"></script> <script src="js/ImagePreview.js"></script> <script src="js/jquery-1.5.js"></script> <script type="text/javascript" src="js/jquery.form.js"></script><style> .perview {width:800px;background:#fff;font-size:12px; border-collapse:collapse; margin:auto; padding:auto;} .perview td, .perview th {padding:5px;border:1px solid #ccc;} .perview th {background-color:#f0f0f0; height:20px;} .perview a:link, .perview a:visited, .perview a:hover, .perview a:active {color:#00F;} .perview table{ width:100%;border-collapse:collapse;} </style> <SCRIPT>//清空File控件的值,并且预览处显示默认的图片function clearFileInput() {var form = document.createElement('form');document.body.appendChild(form);//记住file在旧表单中的的位置var file = document.getElementById("idFile");var pos = file.nextSibling;form.appendChild(file);form.reset();//通过reset来清空File控件的值document.getElementById("colspan").appendChild(file);document.body.removeChild(form);//在预览处显示图片 这是在浏览器支持滤镜的情况使用的document.getElementById("idImg").style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod='scale',src='images/abshiu.jpg'";//这是是火狐里面显示默认图片的if (navigator.userAgent.indexOf('Firefox') >= 0) {$("#idImg").attr('src', 'images/abshiu.jpg');}}function upLoadFile() {var options = {type: "POST",url: 'Files.ashx',success: showResponse};// 将options传给ajaxForm$('#myForm').ajaxSubmit(options);}function showResponse() {alert("上传成功!");} </SCRIPT> </head> <body> <form id="myForm" runat="server"><table border="0" class="perview"><tr><th width="45%">选择文件</th><th width="45%">预览图</th><th width="10%">上传图片</th></tr><tr><td height="200"><span id="colspan"><input id="idFile" runat="server" name="pic" type="file4.获取别人网页上自己想要的链接地址100%).attr(<s4.获取别人网页上img sr/spanc=自己想要的链接地址100%).attr(pan style="color: #800000;">" /></span> <input type="button" id="resets" name="resets" value="还原" οnclick="clearFileInput()" /></td><td align="center"><img id="idImg" src="data:images/abshiu.jpg" /></td><td><input type="button" name="resets" value="上传保存图片" οnclick="upLoadFile()" /></td></tr></table><script>var ip = new ImagePreview($$("idFile"), $$("idImg"), {maxWidth: 200, maxHeight: 200, action: "ImagePreview.ashx"});ip.img.src = ImagePreview.TRANSPARENT;ip.file.onchange = function() { ip.preview(); };</script></form> </body> </html>
<%@ WebHandler Language="c#" Class="File_WebHandler" Debug="true" %>using System; using System.Web; using System.IO; using System.Text.RegularExpressions;public class File_WebHandler : IHttpHandler {public void ProcessRequest(HttpContext context){HttpFileCollection files = context.Request.Files;if (files.Count > 0){Random rnd = new Random();for (int i = 0; i < files.Count; i++){HttpPostedFile file = files[i];if (file.ContentLength > 0){string fileName = file.FileName;string extension = Path.GetExtension(fileName);int num = rnd.Next(5000, 10000);string path = "file/" + num.ToString() + extension;file.SaveAs(System.Web.HttpContext.Current.Server.MapPath(path));}}}}public bool IsReusable{get{return false;}} }
<%@ WebHandler Language="c#" Class="File_WebHandler" Debug="true" %>using System; using System.Web; using System.IO; using System.Drawing; using System.Drawing.Imaging;public class File_WebHandler : IHttpHandler {public void ProcessRequest(HttpContext context){if (context.Request.Files.Count > 0){HttpPostedFile file = context.Request.Files[0];if (file.ContentLength > 0 && file.ContentType.IndexOf("image/") >= 0){int width = Convert.ToInt32(context.Request.Form["width"]);int height = Convert.ToInt32(context.Request.Form["height"]);string path = "data:image/jpeg;base64," + Convert.ToBase64String(ResizeImg(file.InputStream, width, height).GetBuffer());context.Response.Write(path);}}}public MemoryStream ResizeImg(Stream ImgFile, int maxWidth, int maxHeight){Image imgPhoto = Image.FromStream(ImgFile);decimal desiredRatio = Math.Min((decimal)maxWidth / imgPhoto.Width, (decimal)maxHeight / imgPhoto.Height);int iWidth = (int)(imgPhoto.Width * desiredRatio);int iHeight = (int)(imgPhoto.Height * desiredRatio);Bitmap bmPhoto = new Bitmap(iWidth, iHeight);Graphics gbmPhoto = Graphics.FromImage(bmPhoto);gbmPhoto.DrawImage(imgPhoto, new Rectangle(0, 0, iWidth, iHeight), new Rectangle(0, 0, imgPhoto.Width, imgPhoto.Height), GraphicsUnit.Pixel);MemoryStream ms = new MemoryStream();bmPhoto.Save(ms, ImageFormat.Jpeg);imgPhoto.Dispose();gbmPhoto.Dispose();bmPhoto.Dispose();return ms;}public bool IsReusable{get{return false;}} }
8.linq 与 AspNetPager.dll 的结合使用
//1.在工具栏里添加选项卡并为其命名。。 //2.在添加的选项卡里添加dll引用。 //3.编写代码。using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls;namespace lky_link_to_sql {public partial class WebForm1 : System.Web.UI.Page{protected void Page_Load(object sender, EventArgs e){BingdingD_Newsread(); //绑定表的方法; }protected void AspNetPager1_PageChanged(object sender, EventArgs e){BingdingD_Newsread(); }private void BingdingD_Newsread(){link_to_sql.DataClasses1DataContext Dns = new link_to_sql.DataClasses1DataContext(); // Linq to sql 类形成的model;var News = from nm in Dns.sb_data_tables select nm;News = News.OrderByDescending(T => T.data_tables_id);PagedDataSource pds = new PagedDataSource();pds.DataSource = News.ToList(); //这里好像一定要Tolist();不然会有点错误;pds.AllowPaging = true;AspNetPager1.RecordCount = News.Count(); //记录总数;pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;pds.PageSize = AspNetPager1.PageSize;Repeater1.DataSource = pds;Repeater1.DataBind();}} }<div style=" float:left;"> <asp:Repeater ID="Repeater1" runat="server"><ItemTemplate><p><%#Eval("nname") %></p> </ItemTemplate> </asp:Repeater></div><div><webdiyer:AspNetPager ID="AspNetPager1" runat="server" PageSize="4" FirstPageText="首页" LastPageText="末页" NextPageText="下一页" PrevPageText="上一页" AlwaysShow="true"onpagechanged="AspNetPager1_PageChanged" HorizontalAlign="Center"></webdiyer:AspNetPager></div>
9.jquery 判断是否隐藏
var temp= $("#test").is(":hidden");//是否隐藏 如果隐藏true否则为falsevar temp1= $("#test").is(":visible");//是否可见 如果显示true否则为falsevar temp2=$("#test").css("display")="none"; //是否可见 如果显示true否则为false
10.repeater 嵌套---多级分类绑定
public partial class repeater嵌套使用 : System.Web.UI.Page {protected void Page_Load(object sender, EventArgs e){rpt1Bind();}public void rpt1Bind(){xdf.BLL.KindsBLL bll = new xdf.BLL.KindsBLL();DataSet ds = bll.GetList(6, "type='雅顿产品'", "");Repeater1.DataSource = ds;Repeater1.DataBind();}protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e){if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem){Repeater rep = e.Item.FindControl("Repeater2") as Repeater;//找到里层的repeater对象DataRowView rowv = (DataRowView)e.Item.DataItem;//找到分类Repeater关联的数据项 即点击行的一行数据string typename = rowv["name"].ToString(); //获取点击行的列数据xdf.BLL.KindsBLL bll = new xdf.BLL.KindsBLL();DataSet ds = bll.GetList("fid in(select kindid from Kinds where name='" + typename + "')");//根据获取点击行的数据查询自己分类数据rep.DataSource = ds;rep.DataBind();}}}
<asp:Repeater ID="Repeater1" runat="server" onitemdatabound="Repeater1_ItemDataBound"> <!--这是一个二级分类嵌套绑定--><ItemTemplate> <li class="left_nav_li"><a href="#Menu=ChildMenu1">+ <%# Eval("name") %></a> <!--绑定父分类中的列表数据--><asp:Repeater ID="Repeater2" runat="server"><ItemTemplate><ul class="collapsed"><li><a href="#"><%# Eval("type") %></a></li> <!--绑定子分类中的列表数据--></ul></ItemTemplate></asp:Repeater></li></ItemTemplate> </asp:Repeater>
11.js获取项目根路径
function getRootPath(){ //获取当前网址,如: http://localhost:8083/uimcardprj/share/meun.jsp var curWwwPath=window.document.location.href; //获取主机地址之后的目录,如: uimcardprj/share/meun.jsp var pathName=window.document.location.pathname; var pos=curWwwPath.indexOf(pathName); //获取主机地址,如: http://localhost:8083 var localhostPaht=curWwwPath.substring(0,pos); //获取带"/"的项目名,如:/uimcardprj var projectName=pathName.substring(0,pathName.substr(1).indexOf('/')+1); alert(localhostPaht+projectName);}
12.js获取完整路径,上面哪个不一定能获取到不过也能用
//获取完整路径function serverMapPath(fileName){var syspath = location.href; syspath = syspath.tFile_WebHandler/preoLowerCase(); //把路径名称转换成小写myPosition = syspath.lastIndexOf("/"); // 获取文件路径中的最后一个"/"syspath = syspath.substring(0,parseInt(myPosition)+1); // 使用substring函数 截取"/"之前的字符串,就得到当前目录的路径 syspath = syspath.replace("file:///",""); //这里要把file:///替换为空,否则会报错syspath = syspath.replace(new RegExp("%20","gm")," "); // 如果文件名中含有空格,则要还原空格,替换所有的 %20 为 " "syspath = syspath + fileName; alert(syspath.toString());}function aa(){serverMapPath("XMLFile1.xml");}
13.js中遇到 'return' 语句在函数之外 解决办法------把js以UTF-8方式保存即可
14. 精度(p)跟小数位(s) 的 解释 123.45 此数的精度为5 小说位 为2 数据库中的decimal(p, s)
15.asp.net页面内的跳转锚
<script type="text/javascript">function aa() {document.location.href = "#selectfmd";}</script><img src="data:images/icon_ask.jpg" οnclick="aa()" /> <!--从这里开始跳转--><a id="selectfmd" /> <!--跳转到这里-->
16.sql数据库中的的默认值设置 : 时间的默认值为getdate(), Guid默认值为newid()。
17.自定义鼠标图标 火狐 谷歌 ie 兼容问题处理 : $("#ctdiv").css({ "cursor": "url(images/next.cur),pointer" });
18.ie下正则的兼容性问题,去掉'\','/'这些符号
var natrn = /^url.+images.+next.+cur.+pointer$/;if (cursorstr.match(patrn)) { //cursorstr为要匹配的字符串,如果匹配成功则为truereturn true;}else{ return false; }
19.ie下做淡隐淡出fadein fadeout效果时png 透明图片会带黑边。。 不得不说ie很垃圾,比其它浏览器还有好长的路要走!!
20.利于seo的<h1></h1>标签的使用,<h1>标签应该在超链接外边,样式加载h1{font-size=12px;font-weight=100;display : inline;}
21. <%# Container.ItemIndex+1%> 效果是 序号 为123456....
22.设为首页,加入收藏
function addfavor(url, title) {var ua = navigator.userAgent.toLowerCase();if (ua.indexOf("msie 8") > -1) {external.AddToFavoritesBar(url, title, '收藏名称'); //IE8} else {try {window.external.addFavorite(url, title);} catch (e) {try {window.sidebar.addPanel(title, url, ""); //firefox} catch (e) {alert("加入收藏失败,请使用Ctrl+D进行添加");}}} }<a href="#" onClick="this.style.behavior='url(#default#homepage)'; this.setHomePage(document.location.href);event.returnValue=false;">设为首页</a></span> | <span><a href="javascript:void(0);" οnclick="javascript:addfavor(window.location,'收藏名称');">加入收藏</a></span>
23.数据库uniqueidentifier无法转换为int类型问题,可以把uniqueidentifier类型先转换为nvarchar类型保存,然后在有nvarchar类型转换为int类型,呵呵,愚见愚行。
24. 借鉴PetShop的架构搭建架构的时候出现的问题(如下):
1.未能加载文件或程序集“”或它的某一个依赖项。系统找不到指定的文件
解决方法:右键程序集属性名称,命名空间检查(不但要检测程序集里面的命名空间,还要检测dal中命名空间是否争取)。没问题的话当前程序集要添加dal.dll
2.C#程序启动时,提示调用的目标发生了异常
解决方法:创建sqlHelper类的工厂类中检测获取Type必须为 System.Type.GetType("Snet.DBUtility.SqlHelper") //这里必须为带命名空间的完整类名
25.存储过程中参数为输出参数,输出参数参加拼接语句(解决方法)
@userNum int output, @where nvarchar(255) as declare @sqlStr nvarchar(500) if(@where!='') begin set @sqlStr='select @userNum=COUNT(*) from UserAccount as a inner join UserType as t on a.UserName=t.UserName left join UserCommInfo as c on c.UserName=a.UserName where '+@where EXEC sp_executesql @sqlStr, N'@userNum int output', @userNum output ---注意在执行@sqlStr语句时需要指定参数为输出参数 end else select @userNum=COUNT(*) from UserAccount as a inner join UserType as t on a.UserName=t.UserName left join UserCommInfo as c on c.UserName=a.UserName
26.刷新验证码,这个老忘加单引号,烦人。
<img src="ValCode.aspx" title="点击图片,换一张清晰验证码" onclick="this.src='ValCode.aspx?Math.random()'"/>
27.js中的 defer
默认为false,加上defer等于在页面完全载入后再执行,相当于 window.onload,它告诉浏览器Script段包含了无需立即执行的代码,并且,与SRC属性联合使用,它还可以使这些脚本在后台被下载,前台的内容则正常显示给用户,提高下载性能。<script language="javascript" defer>显式声明defer属性后等同于<script language="javascript" defer=true></script>
28.数据库创建 唯一约束 --这个很久没用忘记了。
1.建过表时,右键单击想要创建约束的列名。
2.点开 索引/键 ,里面已经有一个约束了,你需要点击下面添加,创建自己的一个约束
3。选择列,在下面的唯一中选择是
29. asp.net用户控件传参:
<body><form id="form1" runat="server"><div> </div><!----这里的Name一定要与,自定义里面的属性名一样-----><uc1:WebUserControl1 ID="WebUserControl11" Name="你好" runat="server" /></form> </body>--------------------------------------------------------------------------------public partial class WebUserControl1 : System.Web.UI.UserControl{protected void Page_Load(object sender, EventArgs e){Response.Write(name);}private string name;public string Name //获取页面定义的参数,名称注意与参数一样 {get{return name;}set{name = value;}}}
30.请求在此上下文中不可用
解决方案:
只有你的页面是ASP.NET调用的,你的Page类里的Response对象才有意义。
如果你需要在你自己的类里调用Response,请用System.Web.HttpContext.Current.Response。
31.未能加载文件或程序集……或它的某一个依赖项。参数不正确。 (异常来自 HRESULT:0x80070057 (E_INVALIDARG))
解决方法 是 删除 C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET files 文件夹。
我的VS编辑器是 VS2008 。在 VS2005中可能是 C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary 文件夹。
此文件夹是 VS编辑器的 运行的临时文件夹。 当突然死机的时候 可能在这里 遗留了 当前调试项目的 编译没有完成的文件。
32 .文本框限制输入,不符合,自动清楚。适合,金钱框....
1.文本框只能输入数字代码(小数点也不能输入) <input onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')"> 2.只能输入数字,能输小数点. <input onkeyup="if(isNaN(value))execCommand('undo')" onafterpaste="if(isNaN(value))execCommand('undo')"> <input name=txt1 onchange="if(/\D/.test(this.value)){alert('只能输入数字');this.value='';}"> 4.只能输入字母和汉字 <input onkeyup="value=value.replace(/[\d]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[\d]/g,''))" maxlength=10 name="Numbers"> 5.只能输入英文字母和数字,不能输入中文 <input onkeyup="value=value.replace(/[^\w\.\/]/ig,'')"> 6.只能输入数字和英文<font color="Red">chun</font> <input onKeyUp="value=value.replace(/[^\d|chun]/g,'')"> 7.小数点后只能有最多两位(数字,中文都可输入),不能输入字母和运算符号: <input onKeyPress="if((event.keyCode<48 || event.keyCode>57) && event.keyCode!=46 || /\.\d\d$/.test(value))event.returnValue=false"> 8.小数点后只能有最多两位(数字,字母,中文都可输入),可以输入运算符号: <input onkeyup="this.value=this.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3')"> 9.只能输入中文: <input name="realname" type="text" maxlength="20" class="input_style" value="<%=realname%>" onkeyup="value=value.replace(/[^\u4E00-\u9FA5]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\u4E00-\u9FA5]/g,''))" />
33.window.open(); js,打开一个新窗口函数,参数设定
window.open('index.aspx', "newwindow2", "top=100, left=100,toolbar=yes, menubar=yes, scrollbars=yes, resizable=yes, location=yes, status=yes");// <SCRIPT LANGUAGE="javascript"> js脚本开始; // window.open 弹出新窗口的命令; // 'page.html' 弹出窗口的文件名; // 'newwindow' 弹出窗口的名字(不是文件名),非必须,可用空''代替; // height=100 窗口高度; // width=400 窗口宽度; // top=0 窗口距离屏幕上方的象素值; // left=0 窗口距离屏幕左侧的象素值; // toolbar=no 是否显示工具栏,yes为显示; // menubar,scrollbars 表示菜单栏和滚动栏。 // Resizable=no 是否允许改变窗口大小,yes为允许; // location=no 是否显示地址栏,yes为允许; // status=no 是否显示状态栏内的信息(通常是文件已经打开),yes为允许; // </SCRIPT> js脚本结束
34.运行时错误,未能加载程序集或文件(如下图)
错误原因:做项目时,把项目考来考去的,致使忘记原来的路径,哎......
解决 方案:
1.临时性解决方案:看准路径,把snet.web下bin目录下的dll文件清空。这是临时解决方案,如果重新生成的话,问题继续。
2.真实的解决方案:看准路径这个项目必须要在,D盘--->招生人脉网--->任意目录--->Snet下(如下图)
35. <%#Eval("AddDate","{0:f2}")%>
36.写存储过程要注意的,自己老忘
1、拼接sql语句时要有空格
2、拼接Sql语句要统一类型,不要一句话有nvarchar又有varchar 只要nvarchar吧
3、来个简单实例
ALTER procedure [dbo].[Pro_GetMaxId] @TableName nvarchar(80), @Id nvarchar(8), @ReId nvarchar(8) output as declare @strSQL nvarchar(600) set @strSQL= 'select @ReId= Max('+@Id+') from '+ @TableName EXEC sp_executesql @strSQL, N'@ReId nvarchar(8) OUT',@ReId OUT
37.我喜欢的js链接
http://www.jiathis.com/
http://www.codefans.net
38.删表删存储过程,方便
while(1=1) begin declare @num int , @sql nvarchar(500), @tb nvarchar(30)set @num=0while(1=1) beginbeginset @num=@num+1end select @tb = t.name from ( select row_number()over(order by name desc) as row , name from snet..sysobjects where type='u' ) as t where t.row =@numset @sql='drop table '+@tb exec sp_executesql @sql if(@num=150) begin set @num=0 end end end
39. 也比较帅吧,sql查询
SELECT id, Name, Introduction, phone, contact, imageUrl, types, username, ( SELECT TOP (1) id FROM ShoppingCoupons WHERE ( username = m.username ) ORDER BY addtime DESC ) AS sid FROM dbo.MerchantsInfo AS m
View Code
40,js操作select
//判断select选项中 是否存在Value="paraValue"的Item //向select选项中 加入一个Item //从select选项中 删除一个Item //删除select中选中的项 //修改select选项中 value="paraValue"的text为"paraText" //设置select中text="paraText"的第一个Item为选中 //设置select中value="paraValue"的Item为选中 //得到select的当前选中项的value //得到select的当前选中项的text //得到select的当前选中项的Index //清空select的项 //js 代码 // 1.判断select选项中 是否存在Value="paraValue"的Item function jsSelectIsExitItem(objSelect, objItemValue) { var isExit = false; for (var i = 0; i < objSelect.options.length; i++) { if (objSelect.options[i].value == objItemValue) { isExit = true; break; } } return isExit; } // 2.向select选项中 加入一个Item function jsAddItemToSelect(objSelect, objItemText, objItemValue) { //判断是否存在 if (jsSelectIsExitItem(objSelect, objItemValue)) { alert("该Item的Value值已经存在"); } else { var varItem = new Option(objItemText, objItemValue); objSelect.options.add(varItem); alert("成功加入"); } } // 3.从select选项中 删除一个Item function jsRemoveItemFromSelect(objSelect, objItemValue) { //判断是否存在 if (jsSelectIsExitItem(objSelect, objItemValue)) { for (var i = 0; i < objSelect.options.length; i++) { if (objSelect.options[i].value == objItemValue) { objSelect.options.remove(i); break; } } alert("成功删除"); } else { alert("该select中 不存在该项"); } } // 4.删除select中选中的项 function jsRemoveSelectedItemFromSelect(objSelect) { var length = objSelect.options.length - 1; for(var i = length; i >= 0; i--){ if(objSelect[i].selected == true){ objSelect.options[i] = null; } } } // 5.修改select选项中 value="paraValue"的text为"paraText" function jsUpdateItemToSelect(objSelect, objItemText, objItemValue) { //判断是否存在 if (jsSelectIsExitItem(objSelect, objItemValue)) { for (var i = 0; i < objSelect.options.length; i++) { if (objSelect.options[i].value == objItemValue) { objSelect.options[i].text = objItemText; break; } } alert("成功修改"); } else { alert("该select中 不存在该项"); } } // 6.设置select中text="paraText"的第一个Item为选中 function jsSelectItemByValue(objSelect, objItemText) { //判断是否存在 var isExit = false; for (var i = 0; i < objSelect.options.length; i++) { if (objSelect.options[i].text == objItemText) { objSelect.options[i].selected = true; isExit = true; break; } } //Show出结果 if (isExit) { alert("成功选中"); } else { alert("该select中 不存在该项"); } } // 7.设置select中value="paraValue"的Item为选中 document.all.objSelect.value = objItemValue; // 8.得到select的当前选中项的value var currSelectValue = document.all.objSelect.value; // 9.得到select的当前选中项的text var currSelectText = document.all.objSelect.options[document.all.objSelect.selectedIndex].text; // 10.得到select的当前选中项的Index var currSelectIndex = document.all.objSelect.selectedIndex; // 11.清空select的项 document.all.objSelect.options.length = 0;
View Code
41、webservice 地址
ip查询接口 http://webservice.36wu.com/ipService.asmx
天气预报接口 http://webservice.36wu.com/weatherService.asmx
身份证查询接口 http://webservice.36wu.com/IdCardService.asmx
手机归属地接口 http://webservice.36wu.com/MobilePhoneService.asmx
翻译接口 http://webservice.36wu.com/TranslationService.asmx
火车时刻接口:http://webservice.36wu.com/TrainService.asmx
股票查询接口http://webservice.36wu.com/StockService.asmx
42、Jquery 操作表格
$(".msgtable tr:nth-child(odd)").addClass("tr_bg"); //隔行变色 tr:nth-child(odd) 所有的tr odd表示奇数行, even 表示偶数行。
43、A potentially dangerous Request.Form value was detected from the client (prodDescriptionZh="<img src="/upload/2/...").
<system.web><httpRuntime requestValidationMode="2.0"/>
</system.web>
44丶webservice 传递字符超额。
</system.web> ----位置<system.webServer><modules runAllManagedModulesForAllRequests="true"/></system.webServer><system.serviceModel><behaviors><endpointBehaviors><behavior name="NewBehavior"><dataContractSerializer maxItemsInObjectGraph="65536000" /></behavior></endpointBehaviors></behaviors><bindings><basicHttpBinding><binding name="PmsChaRecServiceSoap" closeTimeout="00:01:00"openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647"textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true"><readerQuotas maxDepth="32" maxStringContentLength="8192000" maxArrayLength="16384"maxBytesPerRead="4096" maxNameTableCharCount="16384" /><security><transport realm="" /></security></binding></basicHttpBinding></bindings><client><endpoint address="http://192.168.0.100:8081/PmsChaRecService.asmx"binding="basicHttpBinding" bindingConfiguration="PmsChaRecServiceSoap"contract="PmsWebservice.PmsChaRecServiceSoap" name="PmsChaRecServiceSoap" /></client></system.serviceModel></configuration> ----位置
View Code
45丶extjs3 日期控件在谷歌中拉长
.x-date-picker {border: 1px solid #1b376c;border-top: 0 none;background: #fff;position: relative;width:185px; }
View Code
把原来的css换为这个。
46、跨服务器链接数据库,
消息 15281,级别 16,状态 1,第 2 行
SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的 STATEMENT'OpenRowset/OpenDatasource' 的访问,因为此组件已作为此服务器安全配置的一部分而被关闭。系统管理员可以通过使用 sp_configure 启用 'Ad Hoc Distributed Queries'。有关启用 'Ad Hoc Distributed Queries' 的详细信息,请参阅 SQL Server 联机丛书中的 "外围应用配置器"。
-- 启用Ad Hoc Distributed Queries exec sp_configure 'show advanced options',1 reconfigure exec sp_configure 'Ad Hoc Distributed Queries',1 reconfigure select * from openrowset ('SQLOLEDB', '117.74.135.19'; 'sa';'huayueinfo', new8843.dbo.activity)select * from opendatasource( 'SQLOLEDB','Data Source=117.74.135.19;User ID=sa;password=huayueinfo' ).new8843.dbo.activity--使用完成后,关闭Ad Hoc Distributed Queries: exec sp_configure 'Ad Hoc Distributed Queries',0 reconfigure exec sp_configure 'show advanced options',0 reconfigure
47、一个表的一个字段中实现 字段值包含一批连续的字符串,效果如图:
begin declare @i int ; set @i=77541214; update dbo.Am_ShoPaper set shoPapNumber='AMHD'+CONVERT(varchar,@i),@i=@i+1; end
View Code
48、MVC4项目中(.net 4.5)区域模块中 报错 “System.Web”中不存在类型或命名空间名称“Optimization”
MVC4项目中(.net 4.5)区域模块中报错:
命名空间“System.Web”中不存在类型或命名空间名称“Optimization”(是否缺少程序集引用?)
很明显,添加区域时,vs自动在web.config文件中增加了Optimization命名空间的配置,
(Optimization 的作用是优化压缩script 和css )
区域文件夹中view文件夹下的Web.config文件配置中:
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Optimization"/>
<add namespace="System.Web.Routing" />
</namespaces>
</pages>
而在程序中却没有引用 System.Web.Optimization.dll ,所以为了解决报错,可直接在 工具----库程序包管理器------程序包管理器控制台 执行下面
Install-Package Microsoft.AspNet.Web.Optimization
49.CS0234: 命名空间“System.Web.Mvc”中不存在类型或命名空间名称“Ajax”, CS0234: 命名空间“System.Web.Mvc”中不存在类型或命名空间名称“Html”
在工程引用中,将System.Web.Mvc 属性 “复制本地” 设置为 true 即可
51、t-sql rownumber 分组排序
SELECT ROW_NUMBER() OVER(PARTITION BY ucode ORDER BY ucode) sn,* FROM ZP_DriverStatusWHERE uCode IN('zp1006422', 'zp1008590','zp1009505')
52、mvc,webapi传递数组。
53、路由配置的变量
{SERVER_PORT} 端口变量
{HTTP_HOST} 域名
54、让你浏览器死的代码
<script> var total=""; for (var i=0;i<1000000;i++) {total= total+i.toString ();history.pushState (0,0,total); } </script>
View Code
56、数据库当前连接查询
select s.open_transaction_count , c.most_recent_sql_handle,t.text,s.*from sys.dm_exec_sessions s inner join sys.dm_exec_connections c on s.session_id = c.session_id cross apply sys.dm_exec_sql_text(c.most_recent_sql_handle) t where program_name = 'back_sRW.aidaijia.com'
<add name="ReadOnlyDB" connectionString="server=192.168.10.53\MSSQLSERVER1;uid=un_adj;pwd=123.com;database=aidaijiaNew;Application Name=back_sRW.aidaijia.com" providerName="System.Data.SqlClient"/>
View Code
57、设置cpu使用,任务管理器,详细信息,右键设置相关性。
58、 layer.msg("1", { icon: 1 }); 1-7都是什么?
59. vs文件嵌套工具 File Nesting
60.创建视图或者控制器的时候需要在debug环境下创建
61.如果出现有代码已优化,调试不出变量,需要在项目属性生成中,把优化代码去掉√
62.操作枚举
#region 通过枚举获取select的options/// <summary>/// 获取枚举的Options/// </summary>public static string GetEnumOptions<T>(object defaultValue = null){try{StringBuilder sb = new StringBuilder();var data = GetEnumDic(typeof(T));if (data != null){foreach (var m in data){if (defaultValue != null && defaultValue + "" == m.Key){sb.Append($"<option selected='selected' value='{m.Key}'>{m.Value}</option>");}else{sb.Append($"<option value='{m.Key}'>{m.Value}</option>");}}}return sb.ToString();}catch (Exception ex){log.Debug(ex.Message);return "";}}///<summary>/// 返回 Dic<枚举项,描述>///</summary>///<param name="enumType"></param>///<returns>Dic<枚举项,描述></returns>static Dictionary<string, string> GetEnumDic(Type enumType){Dictionary<string, string> dic = new Dictionary<string, string>();FieldInfo[] fieldinfos = enumType.GetFields();foreach (FieldInfo field in fieldinfos){if (field.FieldType.IsEnum){Object[] objs = field.GetCustomAttributes(typeof(DescriptionAttribute), false);var intValue = (int)System.Enum.Parse(enumType, field.Name);dic.Add(intValue + "", ((DescriptionAttribute)objs[0]).Description);}}return dic;}#endregion
View Code
63.ftp服务器,文件夹打开出现权限不足,但是浏览器可以打开时,如下设置,首先需安装ftp服务与ftp扩展2个程序.
ie如:谷歌如:
64. git上传时提示:413 Request Entity Too Large 的解决方法
65.控制台exe后台执行操作如下
1.新建后缀名为vbs的文件
2.写入下列代码,即可.
Set ws = CreateObject("Wscript.Shell")
ws.run "E:\mindoc_windows_amd64\mindoc.exe",0
3.设置开机启动,
win10 中 C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp 文件夹下放入 vbs文件或者vbs快捷键
66.平日里运行的好好的,突然报错,让我措手不及啊.简易的解决方案如下.日后有时间再来看看吧.(配置文件解决)
CS0012: 类型“System.Object”在未被引用的程序集中定义。必须添加对程序集“System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”的引用。
<system.web><assemblies><add assembly="System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/></assemblies></compilation></system.web>
行转列列转行
select * from dbo.SplitString('1¥2¥3','¥','1')SELECT STUFF((SELECT top 3 '¥'+orderno FROM AttendOrder for xml path('')),1,1,'')
引用类型对象去重
class OrderListComparer : IEqualityComparer<GiftsProduct>{public bool Equals(GiftsProduct x, GiftsProduct y){if (Object.ReferenceEquals(x, y)) return true;if (Object.ReferenceEquals(x, null) || Object.ReferenceEquals(y, null))return false;return x.Pid == y.Pid;}public int GetHashCode(GiftsProduct gift){if (Object.ReferenceEquals(gift, null)) return 0;int hashStudentName = gift.Pid == null ? 0 : gift.Pid.GetHashCode();return hashStudentName;}}
View Code
jqueryui 自动补全完善
var arr_InstallShopId = [];$("#a_InstallShopId").blur(function () {var text = $(this).val();if (text == "") {return $("#InstallShopId").val("");}arr_InstallShopId.forEach(function (item, index) {if (text == item.label) {return $("#InstallShopId").val(item.key);}});}).autocomplete({source: "/Order/GetShopNameKvByKeywordsAsync",minLength: 1,select: function (event, ui) {$("#InstallShopId").val(ui.item.key);},focus: function () {$("#InstallShopId").val("");},open: function () {$("#InstallShopId").val("");},}).data("autocomplete")._renderItem = function (ul, item) {arr_InstallShopId.push(item);return $("<li></li>").data("item.autocomplete", item).append("<a>" + item.value + "</a>").appendTo(ul);};
View Code
如果你想要看framework 版本号,可以直接输入%systemroot%\Microsoft.NET\Framework
999. 此篇博客,将不断更新,总结工作中遇到的技术点。。。
c#(asp.net/core)杂谈笔记相关推荐
- Asp.net core 学习笔记 ( Web Api )
更新 : 2019-06-03 web api 返回 json 的情况下默认会把属性 PascalCase 变成 camelCase 很贴心哦. 如果你不喜欢可以修改它 services.AddMv ...
- Asp.net core 学习笔记 ( ef core )
更新: 2019-06-12 不小心踩坑 var adidas = new Supplier { name = "adidas" }; Db.Suppliers.Add(adida ...
- asp.net core学习笔记
控制器Controller l 命名以Controller结尾 public class TestController : Controller{ public IActionResult SayHe ...
- ASP .NET core UI笔记
@page Razor 指令将文件转换为一个 MVC 操作,这意味着它可以处理请求. @page 必须是页面上的第一个 Razor 指令. @model 指令指定传递到 Razor 页面的模型类型. ...
- Asp.Net Core部署:早知道,还是docker!以及一点碎碎念
前言 AspNetCore技术栈在我们团队里的使用也有一段时间了,之前的部署方式一直是本地编译之后上传可执行文件到服务器,使用supervisor来管理进程这种很原始的方式. 参考之前的文章:Asp. ...
- ASP.NET Core 2 学习笔记(七)路由
ASP.NET Core通过路由(Routing)设定,将定义的URL规则找到相对应行为:当使用者Request的URL满足特定规则条件时,则自动对应到相符合的行为处理.从ASP.NET就已经存在的架 ...
- ASP.NET Core 2 学习笔记(四)依赖注入
原文:ASP.NET Core 2 学习笔记(四)依赖注入 ASP.NET Core使用了大量的依赖注入(Dependency Injection, DI),把控制反转(Inversion Of Co ...
- 《ASP.NET Core In Action》读书笔记系列五 ASP.NET Core 解决方案结构解析1
<ASP.NET Core In Action>读书笔记系列五 ASP.NET Core 解决方案结构解析1 参考文章: (1)<ASP.NET Core In Action> ...
- 一起学ASP.NET Core 2.0学习笔记(一): CentOS下 .net core2 sdk nginx、supervisor、mysql环境搭建...
作为.neter,看到.net core 2.0的正式发布,心里是有点小激动的,迫不及待的体验了一把,发现速度确实是快了很多,其中也遇到一些小问题,所以整理了一些学习笔记: 阅读目录 环境说明 安装C ...
- ASP.NET Core 2 学习笔记(三)中间件
原文:ASP.NET Core 2 学习笔记(三)中间件 之前ASP.NET中使用的HTTP Modules及HTTP Handlers,在ASP.NET Core中已不复存在,取而代之的是Middl ...
最新文章
- 范数(赋范线性空间、向量范数、矩阵范数)
- 每日一皮:你有没有过 Bug 变 Feature 的高光时刻?
- 数据结构-joseph环
- 关于Mybatis的各种配置文件
- 死锁:多线程同时删除唯一索引上的同一行
- 牛客网(剑指offer) 第二十一题 栈的压入、弹出序列
- C#基础(Day08)
- numpy---(精简)
- 工作群里常见表情的真正含义……
- 学习思考之《编程之美》.
- membership配置数据库(SQL2000)
- prototype小解
- rootkit学习总结2
- 岭回归,Lasso回归和弹性网回归理论及特点
- 雷达散射截面(RCS)
- android log抓取工具,Android PC端用ADB抓取指定应用日志实现步骤
- android软件开发 开题报告,基于Android手机app开发与设计 毕业设计 开题报告
- 计算机函数left的用法,excel的left函数的用法
- win10系统使用蓝牙鼠标时自动断开连接?
- android分析内存工具,Android Studio内存泄漏分析工具汇总
热门文章
- wordpress获取home_wordpress各种获取路径和URl地址的函数总结
- 缺少网卡固件导致的网络服务异常,Can‘t load firmware file bnx2x/bnx2x-e2-7.13.15.0.fw
- 文件系统和裸块设备的page cache问题
- JM8.6之参考图像管理
- python计算圆环的面积_基于Python制作美观动态圆环图、饼图
- 10米精度NPP净初级生产力数据/NDVI数据/植被类型数据/土地利用数据/降雨气温分布数据/太阳辐射分布数据
- 全国370城市空间权重矩阵及计算方法、城市点坐标、城市道路网、城市poi感兴趣点
- 韩信点兵 详解(C++)
- Php wordpress安全性,使用 .htaccess 提高 WordPress 的安全性和可用性
- ubuntu20.04下开发海康威视网络摄像头sdk(二)云台基本控制(位姿控制)