C#创建使用一般处理程序.ashx
来源:互联网 发布:淘宝上下架时间设置 编辑:程序博客网 时间:2024/05/29 23:44
<% @ webhandler language="C#" class="testHandler" %>
using System;
using System.Web;
public class testHandler : IHttpHandler
{
public bool IsReusable
{ get { return true; } }
public void ProcessRequest(HttpContext ctx)
{
ctx.Response.ContentType = "text/plain"; //text/html
ctx.Response.Charset = "utf-8";
ctx.Response.StatusCode = 200;
{ get { return true; } }
public void ProcessRequest(HttpContext ctx)
{
ctx.Response.ContentType = "text/plain"; //text/html
ctx.Response.Charset = "utf-8";
ctx.Response.StatusCode = 200;
// ctx.Request.QueryString["abc"];
string title = ctx.Request.Form["title"];
ctx.Response.Write(title);
ctx.Response.Write(" hello");
string title = ctx.Request.Form["title"];
ctx.Response.Write(title);
ctx.Response.Write(" hello");
}
}
---- 发送邮件 Demo ----
<%@ WebHandler Language="C#" Class="MailHandler.GenericMailHandler" %>
using System;
using System.Web;
using System.Net;
using System.Net.Mail;
using System.Text;
namespace MailHandler{
public class GenericMailHandler : IHttpHandler {
public void ProcessRequest (HttpContext ctx) {
ctx.Response.ContentType = "text/plain";
ctx.Response.Charset = "utf-8";
//string _mailServer = "mail.smtp2go.com";
string _mailServer = ctx.Request.Form["mailServer"].ToString();
int _port = Convert.ToInt32(ctx.Request.Form["port"].ToString());
string _username = ctx.Request.Form["username"].ToString();
string _password = ctx.Request.Form["password"].ToString();
string _fromMail = ctx.Request.Form["fromMail"].ToString();
string _toMail = ctx.Request.Form["toMail"].ToString();
string _subject = ctx.Request.Form["subject"].ToString();
string _htmlbody = ctx.Request.Form["htmlbody"].ToString();
if (string.IsNullOrEmpty(_mailServer))
_mailServer = "mail.smtp2go.com";
if (_port==null || _port == 0)
_port = 25;
try
{
MailMessage mail = new MailMessage();
SmtpClient client = new SmtpClient(_mailServer, _port); //Port 8025, 587 and 25 can also be used.
client.Credentials = new NetworkCredential(_username, _password); //use authication code
client.EnableSsl = true;
mail.From = new MailAddress(_fromMail);
mail.To.Add(_toMail);
mail.Subject = _subject;
AlternateView htmlView = AlternateView.CreateAlternateViewFromString(_htmlbody, UTF8Encoding.UTF8, "text/html");
mail.AlternateViews.Add(htmlView);
client.Send(mail);
ctx.Response.Write("Send");
}
catch (Exception ex)
{
ctx.Response.Write(ex.Message);
}
}
public bool IsReusable {
get {
return false;
}
}
}
}
---- 发送邮件 Demo ----
<%@ WebHandler Language="C#" Class="MailHandler.GenericMailHandler" %>
using System;
using System.Web;
using System.Net;
using System.Net.Mail;
using System.Text;
namespace MailHandler{
public class GenericMailHandler : IHttpHandler {
public void ProcessRequest (HttpContext ctx) {
ctx.Response.ContentType = "text/plain";
ctx.Response.Charset = "utf-8";
//string _mailServer = "mail.smtp2go.com";
string _mailServer = ctx.Request.Form["mailServer"].ToString();
int _port = Convert.ToInt32(ctx.Request.Form["port"].ToString());
string _username = ctx.Request.Form["username"].ToString();
string _password = ctx.Request.Form["password"].ToString();
string _fromMail = ctx.Request.Form["fromMail"].ToString();
string _toMail = ctx.Request.Form["toMail"].ToString();
string _subject = ctx.Request.Form["subject"].ToString();
string _htmlbody = ctx.Request.Form["htmlbody"].ToString();
if (string.IsNullOrEmpty(_mailServer))
_mailServer = "mail.smtp2go.com";
if (_port==null || _port == 0)
_port = 25;
try
{
MailMessage mail = new MailMessage();
SmtpClient client = new SmtpClient(_mailServer, _port); //Port 8025, 587 and 25 can also be used.
client.Credentials = new NetworkCredential(_username, _password); //use authication code
client.EnableSsl = true;
mail.From = new MailAddress(_fromMail);
mail.To.Add(_toMail);
mail.Subject = _subject;
AlternateView htmlView = AlternateView.CreateAlternateViewFromString(_htmlbody, UTF8Encoding.UTF8, "text/html");
mail.AlternateViews.Add(htmlView);
client.Send(mail);
ctx.Response.Write("Send");
}
catch (Exception ex)
{
ctx.Response.Write(ex.Message);
}
}
public bool IsReusable {
get {
return false;
}
}
}
}
0 0
- C#创建使用一般处理程序.ashx
- 使用一般处理程序.ashx
- 使用一般处理程序.ashx
- C# ashx一般处理程序Header设置
- 一般处理程序.ashx
- ASHX 一般处理程序
- ashx一般处理程序
- ashx一般处理程序
- C#一般处理程序 ashx.cs使用Session报错的处理
- 创建安全的 ashx (一般处理程序)
- C#网站一般处理程序(ashx)中session的问题
- asp.net .ashx一般处理程序中使用session
- .NET中一般处理程序(ashx)在Ajax中的使用
- asp.net .ashx一般处理程序中使用Session
- .NET中一般处理程序(ashx)在Ajax中的使用
- aspx,ascx和ashx(一般处理程序)使用小结
- 一般处理程序(.ashx)中使用Session (转)
- 在ashx一般处理程序中使用session
- 指针数组以及数组指针
- 测试计算机是小端存储还是大端存储
- js 中时间戳转换格式化日期
- 二维数组和二级指针作为参数传给参数的方式
- 理解数组与指针不可缺少的东西
- C#创建使用一般处理程序.ashx
- 用结构体实现一个电话本
- 结构体中的内存对齐
- 输入数字n,按顺序打印出从1到最大的n位十进制数
- pixhawk的源码结构介绍(针对ArduCopter这套源码)(二)
- 冒泡排序既可以排字符串也可以排字符串
- js note 2
- 浅谈c语言的知识体系
- 顺序链表