本文介绍了Acess拒绝了asp.net中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经制作了一个简单的页面,将新闻添加到具有值标题和链接重定向的网站。

我为此目的使用了xml。

我在本地主机上运行代码它工作正常,但是当我在网站上部署时,只要我试图保存文件就会显示aceess拒绝错误。

我的XML文件是

I have made a simple page to add news to a site which has values title and link to be redirect.
I Have use xml for the purpose.
When i run code on local host it is working perfectly but when i deploy it on website it shows aceess denied error whenever i''m trying to save the file.
My XML file is

<?xml version="1.0" encoding="utf-8"?>
<newsInfo>
  <news>
    <id>1</id>
    <title>AGM (Annual General Meeting) was held on 16th June (Saturday), New Executive Committee has taken charge.</title>
    <link>../contact.aspx</link>
  </news>
  <news>
    <id>2</id>
    <title>IETE Surat  center is thinking to hold its first examination center at SURAT in December 2012, For more Information please  send your feedback here.</title>
    <link>../contact.aspx</link>
  </news>
</newsInfo>







和代码是




And code is

protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["7856_UserID"] == null)
            {
                Response.Redirect("Default.aspx");

            }
            else
            {
                lblUserName.Text = "Welcome " + Convert.ToString(Session["7856_UserID"]) + "!";
                fillgrid();
            }
        }
    }
    protected DataTable retriveDetailsFromXML()
    {
        XDocument xmlDoc = XDocument.Load(Server.MapPath("~\\Data\\newsInfo.xml"));
        var com = from committee in xmlDoc.Descendants("news")
                  select new
                  {
                      id = committee.Element("id").Value,
                      title = committee.Element("title").Value,
                      link = committee.Element("link").Value,
                  };
        DataTable dt = getTable();
        foreach (var c in com)
        {
            DataRow dr = dt.NewRow();
            dr["id"] = c.id;
            dr["title"] = c.title;
            dr["link"] = c.link;
            dt.Rows.Add(dr);
        }
        return dt;
    }
    protected DataTable getTable()
    {
        DataTable dt = new DataTable();
        dt.Columns.Add("id");
        dt.Columns.Add("title");
        dt.Columns.Add("link");
        return dt;
    }
    protected void fillgrid()
    {

        ASPxGridView1.DataSource = retriveDetailsFromXML();
        ASPxGridView1.DataBind();
    }
    protected void btnAddNew_Click(object sender, EventArgs e)
    {
        ASPxGridView1.AddNewRow();
    }
    protected void ASPxGridView1_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e)
    {
            DataTable dt = retriveDetailsFromXML();
            XDocument doc = XDocument.Load(Server.MapPath("~\\Data\\newsInfo.xml"));
            doc.Element("newsInfo").Add(new XElement("news", new XElement("id", Convert.ToInt32(dt.Rows[dt.Rows.Count - 1][0]) + 1), new XElement("title", e.NewValues[0]), new XElement("link", e.NewValues[1])));
            doc.Save(Server.MapPath("~\\Data\\newsInfo.xml"));
            fillgrid();
        
        ASPxGridView1.CancelEdit();
        e.Cancel = true;

    }
    protected void ASPxGridView1_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e)
    {

        if (Session["KeyValue"] != null)
        {
            Int32 key = Convert.ToInt32(Session["KeyValue"]);
            XDocument doc = XDocument.Load(Server.MapPath("~\\Data\\newsInfo.xml"));
            IEnumerable<XElement> com = doc.Elements("newsInfo").Elements("news");
            var oCom = (from member in com
                        where member.Element("id").Value == key.ToString()
                        select member).SingleOrDefault();
            oCom.SetElementValue("title", e.NewValues[0]);
            oCom.SetElementValue("link", e.NewValues[1]);
           
            doc.Save(Server.MapPath("~\\Data\\newsInfo.xml"));
            Session["KeyValue"] = null;
        }
        fillgrid();


        ASPxGridView1.CancelEdit();
        e.Cancel = true;

    }
    protected void ASPxGridView1_StartRowEditing(object sender, DevExpress.Web.Data.ASPxStartRowEditingEventArgs e)
    {
        Session["KeyValue"] = Convert.ToInt32(ASPxGridView1.GetRowValuesByKeyValue(e.EditingKeyValue, "id"));
    }
    protected void ASPxGridView1_RowDeleting(object sender, DevExpress.Web.Data.ASPxDataDeletingEventArgs e)
    {
        XDocument doc = XDocument.Load(Server.MapPath("~\\Data\\newsInfo.xml"));
        doc.Element("newsInfo").Elements("news").Where(x => x.Element("id").Value.Trim() == e.Keys["id"].ToString()).Remove();
        doc.Save(Server.MapPath("~\\Data\\newsInfo.xml"));
        fillgrid();

        e.Cancel = true;
    }



任何1可以告诉我wat是问题。


Can any 1 tell me wat is problem.

推荐答案




这篇关于Acess拒绝了asp.net中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 12:13