我是一位試圖理解他人代碼的新程序員。該程序的目的是使用書籤將MySQL數據放入Word文件模板中。 AR和ICN是兩種類型的報告,因此它們都有自己的模板。該代碼最初只包含AR,我現在添加了ICN。控制檯應用程序運行良好,我遇到了網頁問題。我不明白爲什麼我的代碼中的if (int.TryParse(ticketId, out currentTicket))
是FALSE
,它會生成default.aspx。爲什麼要調用默認的aspx?
試圖查看broswer這個代碼
using System;
using System.Web;
using TicketExtractionLibrary;
namespace TicketExtractionWeb
{
public partial class GetAR : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string ticketId = Request.QueryString["TicketId"];
int currentTicket;
string applicationPath = Request.PhysicalApplicationPath;
ARExtractionController ARController = new ARExtractionController();
string arTemplateLocation = HttpContext.Current.Server.MapPath("~/AR.dot");
string mappingLocation = HttpContext.Current.Server.MapPath("~/ARmapping.xml");
if (int.TryParse(ticketId, out currentTicket))
{
ARController.Extract(currentTicket, applicationPath + "LastTickets", arTemplateLocation, mappingLocation);
Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/msword";
Response.AddHeader("content-transfer-encoding", "binary");
Response.AddHeader("content-disposition", "attachment;filename=AR" + ticketId + ".docx");
Response.ContentEncoding = System.Text.Encoding.GetEncoding(1251);
string path = Server.MapPath(@"\LastTickets\AR" + ticketId + ".docx");
System.IO.FileInfo file = new System.IO.FileInfo(path);
Response.WriteFile(path);
Response.End();
}
else
{
Response.Redirect("Default.aspx");
}
}
}
}
檢查的Request.QueryString [ 「TicketId」]的價值 –
值是10 –