我有一个用于遗留用途的ASHX处理程序文件(我们有一个无法更新的引用ASHX处理程序的Win32应用程序)
以下是处理程序,它似乎可以正常工作,只不过它不会访问MVC应用程序其他位置设置的会话变量:
using Core.Helpers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Script.Serialization;
using System.Web.SessionState;
namespace handlers
{
/// <summary>
/// Summary description for hShowChosenTicketsFGL
/// </summary>
public class hShowChosenTicketsFGL : IHttpHandler, IRequiresSessionState, IReadOnlySessionState
{
public long orderId;
public void ProcessRequest(HttpContext context)
{
List<string> response = new List<string>();
if (context.Session["OrderId"] == null)
orderId = -1;
else
orderId = Convert.ToInt64(context.Session["OrderId"]);
if (orderId == -1)
orderId = Convert.ToInt64(context.Request.QueryString["OrderId"]);
bool ifReturns = false;
if (orderId.ToString().StartsWith("1111"))
ifReturns = true;
if (ifReturns)
orderId = long.Parse(orderId.ToString().Substring(4));
JavaScriptSerializer json = new JavaScriptSerializer();
var fgl = new List<string>();
if(HttpContext.Current.Session["ReceiptFGL"] != null)
{
var text = HttpContext.Current.Session["ReceiptFGL"].ToString();
fgl.Add(text);
HttpContext.Current.Session["ReceiptFGL"] = null;
}
var jsonReponse = json.Serialize(fgl);
context.Response.Write(jsonReponse);
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
我也尝试过路由方法,但无法使其正常工作,该应用程序不断返回并指出未找到该位置。这是我使用的路线:
routes.MapRoute(
name: "LegacyTicketGet",
url: "handlers/hShowChosenTicketsFGL.ashx",
defaults: new { controller = "API", action = "GetReceiptFGL" }
);
没有人知道我可能做错了什么,或者我如何放弃处理程序并使用路由路由到JsonResult操作?