C# ashx后台处理session错误

using DAL;
using Models;
using System.Web.SessionState;

namespace cleaner.ashx
{
    /// <summary>
    /// $codebehindclassname$ 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class UserLogin : IHttpHandler, IRequiresSessionState
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string str = "false";

            if (context.Session["Username"] != null)
            {
                context.Response.Redirect("backindex.aspx");
                context.Response.End();
            }

            string username = context.Request["username"];//接收账号

            if (!string.IsNullOrEmpty(username))
            {
                string pwd = context.Request["pwd"];//接收密码
                if (!string.IsNullOrEmpty(pwd))
                {
                    str = CheckNamePwd(username, pwd);
                }
            }
            context.Response.Write(str);
        }
原文地址:https://www.cnblogs.com/demoC/p/5101750.html