ASP Web API在本地计算机上工作,但不用于生产环境

时间:2019-01-18 06:50:41

标签: asp.net asp.net-web-api

我正在尝试asp.net Web API。我的问题是1个用于发送回pdf字节[]的服务,返回错误500。但是在我的本地计算机上正在运行,并且我已经调试了该服务,但是无法在生产环境中工作。请输入我的代码。

ajax

function printPreview(reqID) {
            var obj = {
                id: reqID
            }
            $.ajax({
                type: "POST",
                url: "/api/default/PrintFormReq/",
                data: JSON.stringify(obj),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (response) {                    
                    var sampleArr = base64ToArrayBuffer(response);

                },
                error: function (response) {
                    alert(response.d);
                }
            });
        }

控件API(后端)

[EnableCors(origins: "*", headers: "*", methods: "*")]
        [HttpPost]
        public byte[] PrintFormReq(mdReqMaster _mdReqMaster)
        {
            string id = _mdReqMaster.id;
            //SQL
            mFunc _mFunc = new mFunc();
            mainDB _mainDB = new mainDB();
            ReportDocument report = new ReportDocument();

            CookieHeaderValue cookie = Request.Headers.GetCookies("uinfo").FirstOrDefault();
            JObject json = JObject.Parse(cookie["uinfo"].Value);

            _mdReqMaster.id = id;

            string query = string.Format(@"select tmp.*
                                        , requestStatus.modify_date as fixed_date
                                        , requestStatus.modify_time as fixed_time
                                        , datediff(day, CONVERT(datetime, (tmp.req_date+' '+tmp.req_time)), CONVERT(datetime, (requestStatus.modify_date+' '+requestStatus.modify_time))) as duration_d
                                        , datediff(hour, CONVERT(datetime, (tmp.req_date+' '+tmp.req_time)), CONVERT(datetime, (requestStatus.modify_date+' '+requestStatus.modify_time))) as duration_h

                                        from
                                        (
                                            select requestMaster.*, '' as base_status_id, '' as base_status
                                            --, datediff(day, CONVERT(datetime, (requestMaster.req_date+' '+requestMaster.req_time)), GETDATE()) as duration_d
                                            --, datediff(hour, CONVERT(datetime, (requestMaster.req_date+' '+requestMaster.req_time)), GETDATE()) as duration_h
                                            , (select top 1 requestStatus.base_req_status_id from requestStatus where requestStatus.req_master_id = requestMaster.id order by requestStatus.id desc) as current_status
                                            from requestMaster 
                                            where requestMaster.id = {0}
                                        ) as tmp
                                        inner join requestStatus on requestStatus.base_req_status_id = '3' and requestStatus.req_master_id = tmp.id", id);


            DataTable dtMaster = new DataTable();
            dtMaster.TableName = "master";
            dtMaster = _mainDB.DTResult(query);

            if (dtMaster.Rows.Count > 0)
            {
                reqMaster dsMaster = new reqMaster();
                mdBaseStatus _mdBaseStatus = new mdBaseStatus();
                _mdBaseStatus = _mFunc.getCurrentStatusByID(_mdReqMaster.id);

                dtMaster.Rows[0]["base_status_id"] = _mdBaseStatus.base_status_id;
                dtMaster.Rows[0]["base_status"] = _mdBaseStatus.base_status;

                //Master
                dsMaster.Tables["master"].ImportRow(dtMaster.Rows[0]);
                //Items
                DataTable dtItems = getItems(_mdReqMaster.id);
                if(dtItems.Rows.Count > 0){
                    foreach(DataRow dr in dtItems.Rows){
                        dsMaster.Tables["items"].ImportRow(dr);
                    }
                }                   
                //TeamTech
                DataTable dtTechnicians = getTechnicians(_mdReqMaster.id);

                //Solution
                DataTable dtSolution = getSolution(_mdReqMaster.id);

                //Evaluate
                DataTable dtEvaluate = getEvaluate(_mdReqMaster.id);


                if (json["Sites_Code"].ToString() == "1067")
                {                    
                    report.Load(Path.Combine(HostingEnvironment.MapPath("~/Reports/SIH/"), "reqSummarySIH.rpt"));
                }
                else if (json["Sites_Code"].ToString() == "1019")
                {
                    report.Load(Path.Combine(HostingEnvironment.MapPath("~/Reports/BSH/"), "reqSummaryBSH.rpt"));
                }



                DataSet ds2 = new DataSet();
                ds2.Tables.Add(dtItems);

                report.Subreports["rpt_items"].SetDataSource(dtItems);
                report.Subreports["rpt_solutions"].SetDataSource(dtSolution);
                report.Subreports["rpt_evaluate"].SetDataSource(dtEvaluate);


                //report.SetDataSource(dsMaster);     

                report.Database.Tables[0].SetDataSource(dsMaster);
            }

            Stream stream = report.ExportToStream(ExportFormatType.PortableDocFormat);
            MemoryStream streamReader = new MemoryStream();
            stream.CopyTo(streamReader);

            return streamReader.ToArray();
        }

这是我的web.config

<system.web>
    <compilation debug="true" targetFramework="4.5">
      <assemblies>
        <!--<add assembly="CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>-->
      </assemblies>
    </compilation>
    <httpRuntime maxRequestLength="2097152" targetFramework="4.5"/>
  </system.web>



  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <handlers>
      <remove name="UrlRoutingHandler"/>
    </handlers>
    <!--<handlers>
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <remove name="OPTIONSVerbHandler" />
      <remove name="TRACEVerbHandler" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>-->
    <security>
      <requestFiltering>
        <requestLimits maxAllowedContentLength="2147483648" />
      </requestFiltering>
    </security>
  </system.webServer>

在我认为也许 requestLimits httpRuntime 的默认设置之前,我已经对其进行了修改,但仍然无法正常工作。请帮忙,非常感谢。

0 个答案:

没有答案