Warning: Undefined array key "HTTP_REFERER" in /www/wwwroot/prod/www.enjoyasp.net/wp-content/plugins/google-highlight/google-hilite.php on line 58
 1,页面放置控件FileUpload
 2,代码:
string FileName = fileUpload1.PostedFile.FileName;
FileName = FileName.Substring(FileName.LastIndexOf("\\") + 1);// 取出文件名的路径(不包括文件的名称)
string upload_file = Server.MapPath("./upload/") + FileName;//取出服务器虚拟路径,存储上传文件
fileUpload1.PostedFile.SaveAs(upload_file);//上传文件


常用属性:

(1)FileUpload1.HasFile用来检查 FileUpload是否有指定文件。

(2)HttpContext.Current.Request.MapPath("~/") 则是获取网站所在的磁盘绝对路径的,如D:\Inetpub\ServerControls\路径,之所以要这么做,是因为FileUpload控件必须指定“绝对路径”,而非相对路径,同时绝对路径也必须有写入权限。

(3)FileUpload1.SaveAs()则是将上传文件存储在磁盘的方法。

(4)FileUpload1.FileName用于获取上传文件名称。

(5)FileUpload1.PostedFile.ContentLength 用于设置或获取上传文件大小,以Byte为单位。

(6)FileUpload1.PostedFile.ContentType 用于设置或获取上传文件的类型 


Warning: Undefined array key "HTTP_REFERER" in /www/wwwroot/prod/www.enjoyasp.net/wp-content/plugins/google-highlight/google-hilite.php on line 58
注意:对于命令行,若路径中带有空格时,如D:\My Documents\a.txt时,将找不到此路径,可采用以下两种方法:  
1,加引号如:"D:\My Documents\a.txt"
2,  变缩写:采用8个字符缩写,即写头六个字母(略去空白),另加波浪号和1 改成:D:\MyDocu~1
  
try
{

    Process p = new Process();

    p.StartInfo.FileName = "cmd";

    p.StartInfo.UseShellExecute = false;

    p.StartInfo.RedirectStandardInput = true;

    p.StartInfo.RedirectStandardOutput = true;

    p.StartInfo.RedirectStandardError = true;

    p.StartInfo.CreateNoWindow = true;

    p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;

    p.Start();

    string strOutput = null;

    string s = @"F:\DownLoad\wenku\FlashPaper2.2\FlashPaper2.2\FlashPrinter.exe " + "\"" + Server.MapPath("~//test.doc") + "\" -o \"" + Server.MapPath("~//test2.swf") + "\"";
   
    p.StandardInput.WriteLine(s);

    p.StandardInput.WriteLine("exit");

    strOutput = p.StandardOutput.ReadToEnd();

    Console.WriteLine(strOutput);

    p.WaitForExit();

    p.Close();

   lblMessage.Text = "success";

}

catch (Exception ex)
{

   lblMessage.Text = ex.ToString();

}


Warning: Undefined array key "HTTP_REFERER" in /www/wwwroot/prod/www.enjoyasp.net/wp-content/plugins/google-highlight/google-hilite.php on line 58

Response输出指定内容,去掉页面自带的内容

//下面的方法,无论当前页面是什么内容,都只输出自己指定的数据。
Response.Clear(); //清除页面前的内容
Response.Write(“hahahahahahahahahhahahahahahahahhahahahaha”); //指定的内容
Response.End(); //之后的内容不再输出


Warning: Undefined array key "HTTP_REFERER" in /www/wwwroot/prod/www.enjoyasp.net/wp-content/plugins/google-highlight/google-hilite.php on line 58
   抓取IP

    REMOTE_ADDR:访问网站的最新的一个IP地址
    HTTP_X_FORWARDED_FOR:中转IP集合即 从出发点到网站前的IP集合,以逗号分开
    1,若直接访问网站,不经过代理,则REMOTE_ADDR为真实IP,HTTP_X_FORWARDED_FOR为空
    2,若使用代理访问网站,则REMOTE_ADDR为最后一个经过的代理IP地址,而HTTP_X_FORWARDED_FOR集合中第一个为真实IP
    由上得出抓取真实IP的方法为:
         private string GetIP()
        {
            if (Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != null)
            {
                return Request.ServerVariables["HTTP_X_FORWARDED_FOR"].Split(new char[] { ',' })[0];
            }
            else
            {
                return Request.ServerVariables["REMOTE_ADDR"];
            }
        }

    注:REMOTE_ADDR此值是不可修改的,因为网站要与代理服务器通信,要给它传数据,若可修改,那么代理服务器就收不到数据了,因此若通过REMOTE_ADDR得到IP,那么此IP一定是真实的。
          HTTP_X_FORWARDED_FOR值是可以修改的,若通过此值取真实IP,有可能是篡改的非真实IP.不过,对于大访问量的网站来说,大部分的客户都是合法的,只有极少的一部分通过篡改IP的方式去访问,在此种情况下,可以适用上述方法得到IP
    不过对于网上投票那种,篡改IP的方式则很有空间,对于此种,就不能再通过IP去确定是不是同一人点击之类,可以写一个加密的cookie来识别。

    //篡改HTTP_X_FORWARDED_FOR
    static void Main(string[] args)
    {
    HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(
    "http://localhost:7867/MyTestWebSite/UserIP.aspx");
    request.Headers.Add("REMOTE_ADDR", "192.168.5.88");
    request.Headers.Add("VIA", "ghj1976");
    request.Headers.Add("X_FORWARDED_FOR", "0.0.0.0");
    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
    StreamReader stream = new
    StreamReader(response.GetResponseStream());
    string info = stream.ReadToEnd();
    stream.Close();
    response.Close();
    request = null;
    Console.Write(info);
    Console.ReadLine();
    }



Warning: Undefined array key "HTTP_REFERER" in /www/wwwroot/prod/www.enjoyasp.net/wp-content/plugins/google-highlight/google-hilite.php on line 58

1,工程都有一*.csproj,直接添加即可。
?2,对于网站,先用IIS指向此网站,然后在解决方案添加的时候 添加现有网站-本地IIS 找到网站,加上即可。


Warning: Undefined array key "HTTP_REFERER" in /www/wwwroot/prod/www.enjoyasp.net/wp-content/plugins/google-highlight/google-hilite.php on line 58

原理:在on blur 或 onkeydown 时显示调用 _doPoastBack事件,回访到服务器端,要执行对应的哪个方法,在前台加hidden指定
如: function btnClick( btn ){
??????????? if (? event.keyCode == 13 &&? btn != undefined ){
??????????????? //btn.click();
??????????????? document.getElementById(“myHidState”).value = btn.id;? //设置input type = ‘hidden’ 的值
??????????????? __doPostBack(btn.id,””);
??????????? }
??????? }
在后台 load时就可据 Request.Forms[“myHidStateName”] 的值要执行对应的方法


Warning: Undefined array key "HTTP_REFERER" in /www/wwwroot/prod/www.enjoyasp.net/wp-content/plugins/google-highlight/google-hilite.php on line 58

? <input type=”text” id = “Text1″ name=”myText111” />
在后台用:Request.Form[“myText111”] 调用前台的值

遍历页面传来的所有值
int loop1;
NameValueCollection coll=Request.Form;?
string[] arr1 = coll.AllKeys;
for (loop1 = 0; loop1 < arr1.Length; loop1++)
{ Response.Write(“Form: ” + arr1[loop1] + “<br>”); }


Warning: Undefined array key "HTTP_REFERER" in /www/wwwroot/prod/www.enjoyasp.net/wp-content/plugins/google-highlight/google-hilite.php on line 58

?

?<input?type=”hidden”?name=”__EVENTTARGET”?id=”__EVENTTARGET”?value=””?/> <input?type=”hidden”?name=”__EVENTARGUMENT”?id=”__EVENTARGUMENT”?value=””?/> function?__doPostBack(eventTarget,?eventArgument)?{ if?(!theForm.onsubmit?||?(theForm.onsubmit()?!=?false))?{ theForm.__EVENTTARGET.value?=?eventTarget; theForm.__EVENTARGUMENT.value?=?eventArgument; theForm.submit(); } }

1,eventTarget? 代表控件ID, eventArgument代表控件对应的数据 可用: Request.Form[“__EVENTTARGET”] 形式获取ID,参数。特别在用CheckBoxList时,在其OnSelectedIndexChanged事件中可通过如下方式获取点击的CheckBox:
?? ? string ClickedItem = Request.Form[“__EVENTTARGET”];//得到用户点击的是哪个
????? ClickedItem = ClickedItem.Split(‘$’)[1];//进行拆分处理
???? chkDepartlist.Items[StringHelper.FormatBlankStringToint(ClickedItem)].Value) //当前点击的CheckBox

2, Button与ImageButton不可通过上述方式得到ID,因为他们没有调用 _doPostBack 方法,是直接submit的方式
?? 不过可用如下方式替换:
?? ???? <input?type=”button”?id=”Button2″?value=”Press?me”?onclick=”DoPostBack()”?/>?? <!–显示调用–>
??? ??? ?<script?language=”javascript”?type=”text/javascript”> ?
?? ??? ??? ??? ?function?DoPostBack()? { ??__doPostBack(‘Button2′,’My?Argument’);????? } ?
?? ??? ??? ?</script> string?passedArgument?=?Request.Params.Get(“__EVENTARGUMENT”);


Warning: Undefined array key "HTTP_REFERER" in /www/wwwroot/prod/www.enjoyasp.net/wp-content/plugins/google-highlight/google-hilite.php on line 58

维护着Application这个类,指示着在程序启动关闭、session启动关闭可做的事情。
如:Application_Start 、Session_Start


Warning: Undefined array key "HTTP_REFERER" in /www/wwwroot/prod/www.enjoyasp.net/wp-content/plugins/google-highlight/google-hilite.php on line 58

int i = (int)Keys.F1; //112
MessageBox.Show(Enum.GetName(typeof(Keys), i)); //F1


Warning: Undefined array key "HTTP_REFERER" in /www/wwwroot/prod/www.enjoyasp.net/wp-content/plugins/google-highlight/google-hilite.php on line 58
public static string GetValue(string AppKey)
        {
            try
            {
                string AppKeyValue;
                AppKeyValue = System.Configuration.ConfigurationSettings.AppSettings.Get(AppKey);
                return AppKeyValue;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public static void SetValue(string AppKey, string AppValue)
        {
            //System.Configuration.ConfigurationSettings.AppSettings.Set(AppKey,AppValue);
            XmlDocument xDoc = new XmlDocument();
            xDoc.Load(System.Windows.Forms.Application.ExecutablePath + ".config");

            XmlNode xNode;
            XmlElement xElem1;
            XmlElement xElem2;
            xNode = xDoc.SelectSingleNode("//appSettings");

            xElem1 = (XmlElement)xNode.SelectSingleNode("//add[@key='" + AppKey + "']");
            if (xElem1 != null) xElem1.SetAttribute("value", AppValue);
            else
            {
                xElem2 = xDoc.CreateElement("add");
                xElem2.SetAttribute("key", AppKey);
                xElem2.SetAttribute("value", AppValue);
                xNode.AppendChild(xElem2);
            }
            xDoc.Save(System.Windows.Forms.Application.ExecutablePath + ".config");
        }


Warning: Undefined array key "HTTP_REFERER" in /www/wwwroot/prod/www.enjoyasp.net/wp-content/plugins/google-highlight/google-hilite.php on line 58

?1,<asp:button ? id=”x” ? runat=”server” ? OnClientClick=”this.disabled=true;document.post.submit();” ? /> ?
? ?
?? 2,设置一全局JS变量
var hasSubmit = 0;
。。。。{
?? ? if ( hasSubmit == 0 ){
??????????????? hasSubmit = 1;
??????????????? return true;
??????????? }else{
??????????????? return false;
??????????? }
}


Warning: Undefined array key "HTTP_REFERER" in /www/wwwroot/prod/www.enjoyasp.net/wp-content/plugins/google-highlight/google-hilite.php on line 58

主要是前一页面的编码格式与后一页面接收时不同造成的,可以在前一页面编码,后一页面解码
编码:System.Web.HttpUtility.UrlEncode(str, Encoding.GetEncoding(“GB2312”));
解码:System.Web.HttpUtility.UrlDecode(aa,System.Text.Encoding.GetEncoding(“Gb2312”));


Warning: Undefined array key "HTTP_REFERER" in /www/wwwroot/prod/www.enjoyasp.net/wp-content/plugins/google-highlight/google-hilite.php on line 58

用\n是不可以的,要用\r\n,主要是因为TextBox运行在Windows上。Windows能够显示的换行必须由两个字符组成:carriage return & line feed,也就是必须是”\r\n”。
为了保证可跨平台,最好用: Environment.NewLine

注:Console, WebForm用 /n是正常的

Environment方法:

1.获取操作系统版本(PC,PDA均支持)
Environment.OSVersion

2.获取应用程序当前目录(PC支持)
Environment.CurrentDirectory

3.列举本地硬盘驱动器(PC支持)
string [] strDrives=Environment.GetLogicalDrives();
foreach(string strDrive in strDrives)
{
?????
}

4.获取.Net Framework版本号(PC,PDA均支持)
Environment.Version

5.获取机器名(PC支持)
EnvironMent.MachineName

6.获取当前环境换行符(PC支持)
Environment.NewLine

7.获取处理器个数(PC支持)
Environment.SystemDirectory

8.获取当前登录用户(PC支持)
Environment.UserName

9.获取系统保留文件夹路径(PC,PDA均支持)
Environment.GetFolderPath(Environment.SpecialFolder对象)
Environment.SpecialFolder对象提供系统保留文件夹标识,例如:Environment.SpecialFolder.Desktop表示桌面文件夹的路径

10.获取命令行参数(PC支持)
string [] strParams=Environment.GetCommandLineArgs();
foreach(string strParam in strParams)
{
?????
}

11.获取系统环境变量(PC支持)
System.Collections.IDictionary dict=Environment.GetEnvironmentVariables();
string str=dict[“Path”].ToString();

12.设置环境变量(PC支持)
Environment.SetEnvironmentVariable(“Path”, “Test”);

13.获取域名(PC支持)
string strUser = Environment.UserDomainName;

14.获取截至到当前时间,操作系统启动的毫秒数(PDA,PC均支持)
str = Environment.TickCount.ToString();

15.映射到当前进程的物理内存数
str = Environment.WorkingSet.ToString();

16.退出应用程序
Environment.Exit(0)


Warning: Undefined array key "HTTP_REFERER" in /www/wwwroot/prod/www.enjoyasp.net/wp-content/plugins/google-highlight/google-hilite.php on line 58

1,新建:右键新增项-外观文件
2,编辑:如
注:没有ID属性
3,应用:在web.config中的 ……….. 这样就为整个网站的button指定了样式
页面级引用: <%@ Page Theme="Skin1" ......... 4,新建多个主题,选择改变,在程序中指定 protected void Page_PreInit(object sender, System.EventArgs e) { try { Theme = "Skin1"; } catch { // Empty strings result in no theme being applied. Theme = ""; } }


Warning: Undefined array key "HTTP_REFERER" in /www/wwwroot/prod/www.enjoyasp.net/wp-content/plugins/google-highlight/google-hilite.php on line 58

中直接加cssClss设置边框,则显示的只是整个table的四边有效果,内部没有线。
若想内部也有边框方法:
(1)this.GridView1.Attributes.Add(“bordercolor”, “red”);
(2)在GridView编辑列里的字段ItemStyle里面设才有用
(3)设置css时为td加上样式
table.gridview_m
{
border-collapse: collapse;
border:solid 1px #93c2f1;
width:98%;
font-size:10pt;
}

table.gridview_m td,th
{
border-collapse: collapse;
border:solid 1px #93c2f1;
font-size:10pt;
}


Warning: Undefined array key "HTTP_REFERER" in /www/wwwroot/prod/www.enjoyasp.net/wp-content/plugins/google-highlight/google-hilite.php on line 58
 引入:System.Net.Mail

        string rtnMsg = "";
        SmtpClient client = new SmtpClient("192.168.16.200");
        MailMessage msg = new MailMessage("@lvshou.com", "zhengxuesong@lvshou.com");
        msg.SubjectEncoding = msg.BodyEncoding = Encoding.GetEncoding("gb2312");
        msg.Subject = "hello";
        msg.Body = "hello,mail";
        try
        {
            client.Send(msg);
            result = true;
            ClientScript.RegisterStartupScript(this.GetType(), "msg", "");
        }

        catch (Exception e1)
        {
            result = false;
            ClientScript.RegisterStartupScript(this.GetType(), "msg", "");
        }


Warning: Undefined array key "HTTP_REFERER" in /www/wwwroot/prod/www.enjoyasp.net/wp-content/plugins/google-highlight/google-hilite.php on line 58

?1,添加ScriptManager
2,添加UpdatePanel,并指定Triggers
3,添加UpdateProgress,在其中添加进度条,或语句


Warning: Undefined array key "HTTP_REFERER" in /www/wwwroot/prod/www.enjoyasp.net/wp-content/plugins/google-highlight/google-hilite.php on line 58

?利用JS执行:_function __doPostBack(eventTarget, eventArgument) {
??? if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
??????? theForm.__EVENTTARGET.value = eventTarget;
??????? theForm.__EVENTARGUMENT.value = eventArgument;
??????? theForm.submit();
??? }
每次实质进行的是form的提交!


Warning: Undefined array key "HTTP_REFERER" in /www/wwwroot/prod/www.enjoyasp.net/wp-content/plugins/google-highlight/google-hilite.php on line 58

?给页面的TextBox设置ReadOnly=”True”时,在后台代码中不能赋值取值,下边几种方法可以避免:

1、不设置ReadOnly,设置onfocus=this.blur()

C#代码 复制代码
  1. <asp:TextBox?ID=”TextBox1″?runat=”server”?onfocus=this.blur()></asp:TextBox>??
<asp:TextBox ID="TextBox1" runat="server" onfocus=this.blur()></asp:TextBox>

文本框不变灰色,但也无法手动修改内容,可以在后台通过Text属性正常赋值取值

2、设置了ReadOnly属性后,通过Request来取值,如下:

前台代码:

C#代码 复制代码
  1. <asp:TextBox?ID=”TextBox1″?runat=”server”?ReadOnly=”True”?></asp:TextBox>??
<asp:TextBox ID="TextBox1" runat="server" ReadOnly="True" ></asp:TextBox>

后台代码:

C#代码 复制代码
  1. string?Text?=?Request.Form[“TextBox1”].Trim();??
string Text = Request.Form["TextBox1"].Trim();

3、在Page_Load()正设置文本框的只读属性,能正常读取,如下:

C#代码 复制代码
  1. protected?void?Page_Load(object?sender,?EventArgs?e) ??
  2. { ??
  3. ????if?(!Page.IsPostBack) ??
  4. ????{ ??
  5. ????????TextBox1.Attributes.Add(“readonly”,”true”); ??
  6. ????} ??
  7. }?