在index.aspx页面有一个导航按纽转到form2.aspx
form2.aspx里面没有加入代码,只放了一个ascx用户控件!
点击按钮在本机测试没有问题,正常转移到form2.aspx,内容显示正常!
=============================================================================可是!!!!我把应用程序放到网上空间就出问题了“/”应用程序中的服务器错误。
--------------------------------------------------------------------------------无法使用前导 .. 在顶级目录上退出。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Web.HttpException: 无法使用前导 .. 在顶级目录上退出。源错误:
[没有相关的源行]
源文件: c:\windows\Microsoft.NET\Framework\v1.1.4322\Temporary ASP.NET Files\root\a9e57569\33856cf2\1xain_zv.0.cs 行: 0 堆栈跟踪:
[HttpException (0x80004005): 无法使用前导 .. 在顶级目录上退出。]
System.Web.Util.UrlPath.Reduce(String path) +700
System.Web.Util.UrlPath.Combine(String basepath, String relative) +296
System.Web.HttpRequest.MapPath(String virtualPath, String baseVirtualDir, Boolean allowCrossAppMapping) +201
System.Web.HttpServerUtility.MapPath(String path) +60
tianfeng.conds..ctor() in c:\inetpub\wwwroot\tianfeng\conds.cs:19
tianfeng.showpro..ctor() in C:\Inetpub\wwwroot\tianfeng\showpro.ascx.cs:18
ASP.showpro_ascx..ctor() in c:\windows\Microsoft.NET\Framework\v1.1.4322\Temporary ASP.NET Files\root\a9e57569\33856cf2\1xain_zv.0.cs:0
ASP.showpro_aspx.__BuildControlShowpro2() in D:\virtualhost\web404905\www\showpro.aspx:93
ASP.showpro_aspx.__BuildControlForm1() in D:\virtualhost\web404905\www\showpro.aspx:14
ASP.showpro_aspx.__BuildControlTree(Control __ctrl) in D:\virtualhost\web404905\www\showpro.aspx:1
ASP.showpro_aspx.FrameworkInitialize() in c:\windows\Microsoft.NET\Framework\v1.1.4322\Temporary ASP.NET Files\root\a9e57569\33856cf2\cuiexq62.0.cs:0
System.Web.UI.Page.ProcessRequest() +84
System.Web.UI.Page.ProcessRequest(HttpContext context) +18
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication+IExecutionStep.Execute() +179
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +87
--------------------------------------------------------------------------------
版本信息: Microsoft .NET Framework 版本:1.1.4322.2032; ASP.NET 版本:1.1.4322.2032
form2.aspx里面没有加入代码,只放了一个ascx用户控件!
点击按钮在本机测试没有问题,正常转移到form2.aspx,内容显示正常!
=============================================================================可是!!!!我把应用程序放到网上空间就出问题了“/”应用程序中的服务器错误。
--------------------------------------------------------------------------------无法使用前导 .. 在顶级目录上退出。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Web.HttpException: 无法使用前导 .. 在顶级目录上退出。源错误:
[没有相关的源行]
源文件: c:\windows\Microsoft.NET\Framework\v1.1.4322\Temporary ASP.NET Files\root\a9e57569\33856cf2\1xain_zv.0.cs 行: 0 堆栈跟踪:
[HttpException (0x80004005): 无法使用前导 .. 在顶级目录上退出。]
System.Web.Util.UrlPath.Reduce(String path) +700
System.Web.Util.UrlPath.Combine(String basepath, String relative) +296
System.Web.HttpRequest.MapPath(String virtualPath, String baseVirtualDir, Boolean allowCrossAppMapping) +201
System.Web.HttpServerUtility.MapPath(String path) +60
tianfeng.conds..ctor() in c:\inetpub\wwwroot\tianfeng\conds.cs:19
tianfeng.showpro..ctor() in C:\Inetpub\wwwroot\tianfeng\showpro.ascx.cs:18
ASP.showpro_ascx..ctor() in c:\windows\Microsoft.NET\Framework\v1.1.4322\Temporary ASP.NET Files\root\a9e57569\33856cf2\1xain_zv.0.cs:0
ASP.showpro_aspx.__BuildControlShowpro2() in D:\virtualhost\web404905\www\showpro.aspx:93
ASP.showpro_aspx.__BuildControlForm1() in D:\virtualhost\web404905\www\showpro.aspx:14
ASP.showpro_aspx.__BuildControlTree(Control __ctrl) in D:\virtualhost\web404905\www\showpro.aspx:1
ASP.showpro_aspx.FrameworkInitialize() in c:\windows\Microsoft.NET\Framework\v1.1.4322\Temporary ASP.NET Files\root\a9e57569\33856cf2\cuiexq62.0.cs:0
System.Web.UI.Page.ProcessRequest() +84
System.Web.UI.Page.ProcessRequest(HttpContext context) +18
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication+IExecutionStep.Execute() +179
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +87
--------------------------------------------------------------------------------
版本信息: Microsoft .NET Framework 版本:1.1.4322.2032; ASP.NET 版本:1.1.4322.2032
{
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO; using System.Data.OleDb;
/// <summary>
/// proguanli 的摘要说明。
/// </summary>
/// System.Web.HttpContext.Current.Server.MapPath() //再类里面用MapPath方法
public class proguanli : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.DataGrid DataGrid1;
protected System.Web.UI.WebControls.Label Label1;
conds cd=new conds();
OleDbConnection olecon;
private void Page_Load(object sender, System.EventArgs e)
{
DataSet ds=cd.imgshow();
DataGrid1.DataSource=ds;
if(!IsPostBack)
{
DataGrid1.DataBind();
}
} #region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器
/// 修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.DataGrid1.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.DataGrid1_PageIndexChanged);
this.DataGrid1.CancelCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_CancelCommand);
this.DataGrid1.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_EditCommand);
this.DataGrid1.UpdateCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_UpdateCommand);
this.DataGrid1.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_DeleteCommand);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion private void DataGrid1_CancelCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
DataGrid1.EditItemIndex=-1;
this.DataBind();
} private void DataGrid1_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
// Session["path"]=Server.MapPath("");
string strid=(string)DataGrid1.DataKeys[(int)e.Item.ItemIndex];
string url=(Server.MapPath("image/chanpin/")+strid+".gif");
if(File.Exists(url)) //检查文件是否存在
{
// File.Delete(url); //删除文件
}
try
{
// cd.Delete(strid);
DataGrid1.DataSource=cd.imgshow();
DataGrid1.DataBind();
}
catch(Exception e1)
{
Response.Redirect("guanli.aspx");
}
} private void DataGrid1_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
DataGrid1.EditItemIndex=e.Item.ItemIndex;
DataGrid1.DataBind();
((TextBox)DataGrid1.Items[e.Item.ItemIndex].Cells[4].Controls[0]).Width=40;
((TextBox)DataGrid1.Items[e.Item.ItemIndex].Cells[5].Controls[0]).Width=40;
((TextBox)DataGrid1.Items[e.Item.ItemIndex].Cells[6].Controls[0]).Width=200;
} private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
DataGrid1.CurrentPageIndex=e.NewPageIndex;
this.DataBind();
}
private void DataGrid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string strid=(string)DataGrid1.DataKeys[(int)e.Item.ItemIndex];
// string strname=Convert.ToString(( (TextBox)e.Item.Cells[4].Controls[0] ).Text);
// string strprice=Convert.ToString(( (TextBox)e.Item.Cells[5].Controls[0] ).Text);
// string strintro=Convert.ToString(( (TextBox)e.Item.Cells[6].Controls[0] ).Text);
olecon=new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("../tianfeng/tianfeng.mdb"));
String myupdateCmd = "update img set name=@name,price=@price,intro=@intro where id='"+strid+"'";
OleDbCommand Scmd = new OleDbCommand(myupdateCmd,olecon);// Scmd.Parameters.Add(new OleDbParameter("@id",OleDbType.VarChar,10));
// Scmd.Parameters["@id"].Value = ((Label)e.Item.Cells[3].Controls[0]).Text;
Scmd.Parameters.Add(new OleDbParameter("@name",OleDbType.VarChar,10));
Scmd.Parameters["@name"].Value = ( (TextBox)e.Item.Cells[4].Controls[0] ).Text;
Scmd.Parameters.Add(new OleDbParameter("@price",OleDbType.VarChar,10));
Scmd.Parameters["@price"].Value = ( (TextBox)e.Item.Cells[5].Controls[0] ).Text;
Scmd.Parameters.Add(new OleDbParameter("@intro",OleDbType.VarChar,50));
Scmd.Parameters["@intro"].Value = ( (TextBox)e.Item.Cells[6].Controls[0] ).Text; Scmd.Connection.Open();
try
{
Scmd.ExecuteNonQuery();
}
catch(Exception exc)
{
Label1.Visible=true;
Label1.Text = exc.ToString() + "错误:无法更新纪录,请确保正确填写字段!";
DataGrid1.EditItemIndex=-1;
}
// Label1.Visible=true;
DataGrid1.EditItemIndex=-1;
Scmd.Connection.Close();
DataGrid1.DataSource=cd.imgshow();
DataGrid1.DataBind();
}
}
}
^^^^^^
看见没有是这里出错了.为了安全目的,很多服务器禁止了父目录.简单的说就是不允许使用../
你需要在编写代码的时候注意这点.