IIS主机后我无法访问的ASP.NET Web应用程序 [英] ASP.NET web application I Can’t Access after IIS hosting
本文介绍了IIS主机后我无法访问的ASP.NET Web应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我必须使用Microsoft.Office.Interop.Excel命名空间读取存在的Excel工作表值并生成文本格式报告,当我在Windows服务器8上的IIS 7.5上部署ASP.NET Web应用程序时,我无法访问IIS托管后的事件,但是当我运行本地机器时它会正常工作...请帮我解决这个问题?关注我的aspx.cs代码。
I have to read an exist excel sheet values and generate text format report using Microsoft.Office.Interop.Excel namespace, when I deploy an ASP.NET web application on IIS 7.5 at windows server 8 r2 I can't access that event after IIS hosting but when I run local machine it'll working fine... kindly give me the solution on this problem? Following my aspx.cs code.
using System.Data;
using System.Reflection;
using System.Text;
using System.IO;
using Microsoft.Office.Interop.Excel;
public void GetTextValue()
{
string sUploadFilePath = string.Empty;
sUploadFilePath = Server.MapPath(".") + @"\Report\GAD_Model_Template_keivsan1_D2038_00.xls";
DataSet ds = new DataSet();
//Office Application Object Declaretion
Microsoft.Office.Interop.Excel.Application oXL = null;
//Office workbook object Declaretion
Microsoft.Office.Interop.Excel.Workbook oWB = null;
//Office Worksheet object Declaretion
Microsoft.Office.Interop.Excel.Worksheet oSheet = null;
//Office Range object Declaretion
Microsoft.Office.Interop.Excel.Range oRng = null;
try
{
//Create an Application object
oXL = new Microsoft.Office.Interop.Excel.Application();
//Getting a WorkBook object
oWB = oXL.Workbooks.Open(sUploadFilePath, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
//Getting a WorkSheet object
oSheet = (Microsoft.Office.Interop.Excel.Worksheet)oWB.Sheets["OUTPUT"];
//Datatable with dtExcel Name
System.Data.DataTable dt = new System.Data.DataTable("dtExcel");
ds.Tables.Add(dt);
DataRow dr;
StringBuilder sb = new StringBuilder();
//Total Column Count
int jValue = oSheet.UsedRange.Cells.Columns.Count;
//Total Row count
int iValue = oSheet.UsedRange.Cells.Rows.Count;
for (int j = 1; j <= jValue; j++)
{
dt.Columns.Add("column" + j, System.Type.GetType("System.String"));
}
//Getting Data in Cell
for (int i = 1; i <= iValue; i++)
{
dr = ds.Tables["dtExcel"].NewRow();
for (int j = 1; j <= jValue; j++)
{
oRng = (Microsoft.Office.Interop.Excel.Range)oSheet.Cells[i, j];
string strValue = oRng.Text.ToString();
dr["column" + j] = strValue;
}
ds.Tables["dtExcel"].Rows.Add(dr);
}
//Release the Excel objects
oWB.Close(false, System.Reflection.Missing.Value, System.Reflection.Missing.Value);
oXL.Workbooks.Close();
oXL.Quit();
oXL = null;
oWB = null;
oSheet = null;
oRng = null;
GC.GetTotalMemory(false);
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
GC.GetTotalMemory(true);
//Release the Excel objects
StringBuilder commaDelimitedText = new StringBuilder();
commaDelimitedText.AppendLine("GAD Inputs");
foreach (DataRow row in ds.Tables["dtExcel"].Rows)
{
string value = string.Format("{0}", row[0]); // how you format is up to you (spaces, tabs, delimiter, etc)
commaDelimitedText.AppendLine(value);
}
File.WriteAllText("" + Server.MapPath(".") + @"\Report\" + "GADoutput" + ".txt" + "", commaDelimitedText.ToString());
string txtfilepath = Server.MapPath(".") + @"\Report\" + "GADoutput" + ".txt";
Session["filepath"] = txtfilepath;
ScriptManager.RegisterStartupScript(this, typeof(string), "SITE", "alert('Text File write successfully!');", true);
}
catch (Exception ex)
{ }
//return ds;
}
< br $>
谢谢和问候,
Parthiban K.
Thanks and regards,
Parthiban K.
推荐答案
hi,
请检查您的Web应用程序应用程序池
please check your web applications application pool
这篇关于IIS主机后我无法访问的ASP.NET Web应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文