ASP .ashx文件

1. 数据类型

基本数据类型: 整型(int short long float double)字符型(char) 字符串(string) decimal(这个类型可以根据输入的数来定义自己是什么整型)
无符号类型 : uint、就是基本类型前面加u

注意:如果是 无符号整型,那么如果内容溢出,就会归零 不会溢出

2. 请求类型
在html设置发送方式,默认get方式
在这里插入图片描述
在这里插入图片描述

 try
            {
                var userName = context.Request["acount"];
                var userPassword = context.Request["pwd"];
                Convert.ToInt32(userName);
                Convert.ToInt32(userPassword);
            }
            catch (Exception)
            {

                context.Response.Write("输入信息格式错误,请仔细核对");
            }
            context.Response.Write("Hello World");
            context.Response.End(); //停止程序
            return;  //停止程序(常用)

3. 画布的设置

 context.Response.ContentType = "text/Image";
 *********************************
using (Bitmap bmp = new Bitmap(500, 500))  //创建一个尺寸为500*500的内存图像
                {
                    HttpRequest request = context.Request;
                    using (Graphics grap = Graphics.FromImage(bmp))//得到图片的画布
                    {
                        using (Font font = new Font(FontFamily.GenericSerif, 30))
                        {
                            grap.DrawString(image + "nice to meet you", new Font(FontFamily.GenericSerif, 30), Brushes.Red, 0, 0);
                            //grap.DrawString("浏览器:" + request.Browser.Browser + request.Browser.Version, font, Brushes.Red, 0, 50);
                            grap.DrawString("操作系统:" + request.Browser.Platform, font, Brushes.Red, 0, 50);
                            bmp.Save(@"G:\source\Asp.NETashx\2.png", ImageFormat.Png);
                        }
                    }
                }

4.文件上传

1)在form标签 设置属性 method = “post” enctype=“multipart/form-data”
2)ashx文件中,设置获取文件上传信息的对象 HttpPostFile file =context.Request.Files[“file”]
3)上传后,将上传的文件 保存:记得设置保存路径: string location = context.Server.MapPath("~/upload") + “/” + file.FileName;
file.SaveAs(location);

   <input type="file" name="file"   />    <br/>
   <input type="submit" value="上传"/>
  </form>
  ********************
   context.Response.ContentType = "text/html";
    HttpPostedFile file = context.Request.Files["file"]; //或许Html发送过来的文件
    if(file.contentLength <=0)
    {
    	context.Response.Write("请选择要上传的文件");
    	return;
   	}
    
        if (file.ContentLength > 1024 * 1024)
        {
            context.Response.Write("文件不能大于1M");
            return;
        }
        if (file.ContentType != "image/jpeg" && file.ContentType != "image/gif")
        {
            context.Response.Write("文件类型不允许");
            return;
        }
        string location = context.Server.MapPath("~/upload") + "/" + file.FileName;
        file.SaveAs(location);
        context.Response.Write(location);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值