Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Upomoc zasto mi ovaj ASPNET kod ne radi?
Author Message
vselak Offline
Novi korisnik
*

Posts: 7
Joined: Jul 2007
Reputation: -1
Post: #1
Sad Upomoc zasto mi ovaj ASPNET kod ne radi?
Evo problema:
Xml kod izgleda ovako:

<?xml version="1.0"?>
<Entry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Title>Hello!</Title>
<Details>These are the details of the ulaza</Details>
<Entry>

Koda za Global.asax,ovako:

using System;
using System.Collections;
using System.ComponentModel;
using System.Web;
using System.Web.SessionState;
using System.IO;
using System.Xml.Serialization;

namespace WebApplication1
{
/// <summary>
/// Summary description for Global.
/// </summary>
public class Global : System.Web.HttpApplication
{
/// <summary>
/// Required designer variable.
/// </summary>
/// members...
public static String EntryFilePath;
private System.ComponentModel.IContainer components = null;

public Global()
{
InitializeComponent();
}

protected void Application_Start(Object sender, EventArgs e)
{
//postavljamo putanju deljenog clana...
EntryFilePath=Server.MapPath("Entries");

}

protected void Session_Start(Object sender, EventArgs e)
{

}

protected void Application_BeginRequest(Object sender, EventArgs e)
{

}

protected void Application_EndRequest(Object sender, EventArgs e)
{

}

protected void Application_AuthenticateRequest(Object sender, EventArgs e)
{

}

protected void Application_Error(Object sender, EventArgs e)
{

}

protected void Session_End(Object sender, EventArgs e)
{

}

protected void Application_End(Object sender, EventArgs e)
{

}
public static Entry LoadEntry(String filename)
{
String filepath=EntryFilePath+"\\" +filename;
FileStream file = new FileStream(filepath,FileMode.Open);
XmlSerializer serializer=new XmlSerializer(typeof(Entry));
Entry newEntry=(Entry)serializer.Deserialize(file);
file.Close();

return newEntry;
}

Za klasu Entry.cs,ovako:

using System;
using System.IO;
using System.Xml.Serialization;

namespace WebApplication1
{
/// <summary>
/// Summary description for Entry.
/// </summary>
public class Entry
{
//members...
public DateTime_timestamp;
public String_title;
public String_details;
[XmlIgnore()] public DateTime Timestamp
{
get
{
return_timestamp;
}
set
{
_timestamp=value;
}
}
public String Title
{
get
{
return_title;
}
set
{
_title=value;
}
}
public String Details
{
get
{
return_details;
}
set
{
_details=value;
}
}
public Entry()
{
//
// TODO: Add constructor logic here
//
}

Za WebForm1.aspx.cs ovako:

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace WebApplication1
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label labelServerPath;
protected System.Web.UI.WebControls.Label labelEntryTitle;
protected System.Web.UI.WebControls.Label labelEntryDetails;
protected System.Web.UI.WebControls.Label labelCopyright;

private void Page_Load(object sender, System.EventArgs e)
{
// koja je godina?
int year = DateTime.Now.Year;
if(year==2001)
labelCopyright.Text="Copyright &copy; Disraeli "+year;
else
labelCopyright.Text="Copyright &copy;Disraeli 2001-"+year;
//Postavljamo putanju servera...
labelServerPath.Text=Global.EntryFilePath;
Entry entry=Global.LoadEntry("Entry.xml");
labelEntryTitle.Text=entry.Title;
labelEntryDetails.Text=entry.Details;

}

Za WebForm1.aspx,ovako:

<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="WebApplication1.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<div>Disraeli's Weblog
</div>
<br>
<div>
<asp:Label id="labelEntryTitle" runat="server">entryTitle</asp:Label></div>
<div>
<asp:Label id="labelEntryDetails" runat="server">entryDetails</asp:Label></div>
<div>&nbsp;
<asp:label id="labelCopyright" runat="server">copyright</asp:label></div>
<br>
<div>
<asp:Label id="labelServerPath" runat="server">serverpath</asp:Label>
</div>
</form>
</body>
</HTML>

Dobijam izvestaj o gresci ovakav:

c:\inetpub\wwwroot\WebApplication1\Entry.cs(15): Invalid token ';' in class, struct, or interface member declaration
c:\inetpub\wwwroot\WebApplication1\Entry.cs(14): Invalid token ';' in class, struct, or interface member declaration
c:\inetpub\wwwroot\WebApplication1\Entry.cs(13): Invalid token ';' in class, struct, or interface member declaration

A u explorer-u to izgleda ovako:

Disraeli's Weblog

entryTitle
entryDetails
Copyright ©Disraeli 2001-2007

c:\inetpub\wwwroot\WebApplication1


Zasto mi necita podatke iz Xml-koda: <Title>Hello!</Title>
<Details>These are the details of the ulaza</Details>
Nego mi izbacuje:

entryTitle-umesto----Hello
entryDetails-umesto---These are details of the…
Confused
30-07-2007 08:42 PM
Find all posts by this user Quote this message in a reply
Puž Offline
Redoviti posjetitelj
**

Posts: 132
Joined: Mar 2007
Reputation: 25
Post: #2
RE: Upomoc zasto mi ovaj ASPNET kod ne radi?
Pozdrav vselče. Fakat ne kužim zakej si ovo zakompliciro do daske. Zakej si global asu ubacivao sim kad ti fakat netreba? No ko ga je*e.

Ispravio sam ti dosta sitnica kaj mi se nisu sviđale, al glavna greška ti je u entry.cs-u kod baratanja sa varijablama.
Code:
public DateTime_timestamp;
public String_title;
public String_details;
Sjebo si kaj si tip podataka od imena varijable odvajao sa '_' znakićem, a tak to nejde, te kaj si kasnije te varijable pozivao sa '_'.

Xml si ostavi kakav je (samo zatvori root tag), global.asax.cs i global.asax nemoj koristit uopče, i evo rješenja:

WebForm1.aspx (kod mene je default.aspx):
Code:
<%@ Page language="c#" Codebehind="default.aspx.cs"  Inherits="WebApplication1.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<div>Disraeli's Weblog
</div>
<br>
<div>
<asp:Label id="labelEntryTitle" runat="server">entryTitle</asp:Label></div>
<div>
<asp:Label id="labelEntryDetails" runat="server">entryDetails</asp:Label></div>
<div>&nbsp;
<asp:label id="labelCopyright" runat="server">copyright</asp:label></div>
<br>
<div>
<asp:Label id="labelServerPath" runat="server">serverpath</asp:Label>
</div>
</form>

</body>
</HTML>

WebForm1.aspx.cs (kod mene default.aspx.cs)

Code:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Xml.Serialization;
using System.IO;


namespace WebApplication1
{
    /// <summary>
    /// Summary description for WebForm1.
    /// </summary>
    public class Entry
    {  
        public DateTime timestamp;
        public String title;
        public String details;
    
        [XmlIgnore()] public DateTime Timestamp
        {
            get {return timestamp;}
            set {timestamp=value;}
        }
        public String Title
        {
            get {return title;}
            set {title=value;}
        }
        public String Details
        {
            get {return details; }
            set {details=value;}
        }
        public Entry(){}
    }
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected System.Web.UI.WebControls.Label labelServerPath;
        protected System.Web.UI.WebControls.Label labelEntryTitle;
        protected System.Web.UI.WebControls.Label labelEntryDetails;
        protected System.Web.UI.WebControls.Label labelCopyright;

        public static String EntryFilePath;
        
        public static Entry LoadEntry(String filename)
        {
            string filepath = "c:\\inetpub\\wwwroot\\webapplication1\\";
            FileStream file = new FileStream(filepath+filename, FileMode.Open);
            XmlSerializer serializer = new XmlSerializer(typeof(Entry));
            Entry newEntry = (Entry)serializer.Deserialize(file);
            file.Close();
            
            return newEntry;
        }
  
        private void Page_Load(object sender, System.EventArgs e)
        {
            // koja je godina?
            int year = DateTime.Now.Year;
            if (year == 2001)
                labelCopyright.Text = "Copyright &copy; Disraeli " + year;
            else
                labelCopyright.Text = "Copyright &copy;Disraeli 2001-" + year;
            //Postavljamo putanju servera...
            labelServerPath.Text = EntryFilePath;
          
            Entry entry = LoadEntry("Entry.xml");
  

            labelEntryTitle.Text = entry.Title;
            labelEntryDetails.Text = entry.Details;
        }

    }
}
02-08-2007 08:07 PM
Find all posts by this user Quote this message in a reply
vselak Offline
Novi korisnik
*

Posts: 7
Joined: Jul 2007
Reputation: -1
Post: #3
RE: Upomoc zasto mi ovaj ASPNET kod ne radi?
Hvalati puno ne znas koliko si mi pomogao rpobacu pa cu videti.Inace u medjuvremenu sam probao da izbacim crtice u definiciji polja,onda mi je VS-prijavljivao da nema greske,ali mi je onda server prijavljivao gresku tipa:

Server Error in '/WebApplication1' Application.
--------------------------------------------------------------------------------

Access to the path "c:\inetpub\wwwroot\WebApplication1\Entries\Entry.xml" is denied.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.UnauthorizedAccessException: Access to the path "c:\inetpub\wwwroot\WebApplication1\Entries\Entry.xml" is denied.

ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6) that is used if the application is not impersonating. If the application is impersonating via <identity impersonate="true"/>, the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.

To grant ASP.NET write access to a file, right-click the file in Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access.

Source Error:


Line 70: {
Line 71: String filepath=EntryFilePath+"\\" +filename;
Line 72: FileStream file = new FileStream(filepath, FileMode.Open);
Line 73: XmlSerializer serializer=new XmlSerializer(typeof(Entry));
Line 74: Entry newEntry=(Entry)serializer.Deserialize(file);


Source File: c:\inetpub\wwwroot\WebApplication1\Global.asax.cs Line: 72

Stack Trace:


[UnauthorizedAccessException: Access to the path "c:\inetpub\wwwroot\WebApplication1\Entries\Entry.xml" is denied.]
System.IO.__Error.WinIOError(Int32 errorCode, String str) +393
System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath, Boolean bFromProxy) +888
System.IO.FileStream..ctor(String path, FileMode mode) +52
WebApplication1.Global.LoadEntry(String filename) in c:\inetpub\wwwroot\WebApplication1\Global.asax.cs:72
WebApplication1.WebForm1.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\webapplication1\webform1.aspx.cs:34
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +750




--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.2032; ASP.NET Version:1.1.4322.2032

Sta sad to znaci?Izvini ako ispadam glup,ali ja sam relativno nov u ASPNET-u pa me sve buni.Moj VS je 2003,da li mi je kod za XML,neodgovarajuci posto radim sa njigom koja se bazira na malo starijem VS-u.
Inace po obavestenju servera,greska je u ovom redu:

Line 72: FileStream file = new FileStream(filepath, FileMode.Open);
Fakticki ne otvara xml-kod a ja pojma nemam zasto?
Pomagaj ako mozes?
Mozda je ovo starija komanda iz nekog predjasnjeg VS(mislim NET-platforme),a ja sam je nasao u knjizi iz 2001,dok je moj VS 2003.Pa je sad verovatno malo izmenjena a ja nisam obavesten.
Nemam pojma jos sam zelen u ovome.priznajem,ko moze nek p[omogne.
Sta si podrazumevao pod tim da u xml-kodu zatvorim root tag,pa zar nije zatvoren?Sada cu da primenim tvoje resenje,mada me zarko zanima sto ovaj kod iz knjige sa klasom Global.asax ne radi.I sto mi izbacuje gore navedenu gresku.Kakva je ovo definicija polja :
private String_title????

Ja iz C# znam ono sto si mi ti rekao( private string title).

Posto nesto znam o C# ali tek ucim o ASPNET-u.A u knjizi Beginning C#
iz 2001 od Karli Watson-a u ASPNET- su tako definisana polja.



3 posta spojena u jedan. Ne bi ti skodilo da procitas pravila, a?

-by hurmash1ca
04-08-2007 03:48 PM
Find all posts by this user Quote this message in a reply
Puž Offline
Redoviti posjetitelj
**

Posts: 132
Joined: Mar 2007
Reputation: 25
Post: #4
RE: Upomoc zasto mi ovaj ASPNET kod ne radi?
Xml ti nije dobar

<?xml version="1.0"?>
<Entry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <Title>Hello!</Title>
  <Details>These are the details of the  ulaza</Details>
<Entry> <!--treba biti </Entry>-->

A greska ti je u tome što ti nije dozvoljen pristup Xml fajlu preko .net-a.
Odi u exploreru do xml fajla, lupi desni klik - Properties, odi na Security tab i dolje buš vidil check box-ove na kojima za sve selektiraj Allow polja.
04-08-2007 07:24 PM
Find all posts by this user Quote this message in a reply
vselak Offline
Novi korisnik
*

Posts: 7
Joined: Jul 2007
Reputation: -1
Post: #5
RE: Upomoc zasto mi ovaj ASPNET kod ne radi?
Sto se tice xml-koda u pravu si nisam bio zatvorio tag.A sto se tice toga da omogucim pristup net-a xml-u,pokusavao sam.Skapirao sam poruku ali nigde nema tih polja za cekiranje ili ja ne znam gde da ih nadjem.Kada kliknem desnim klikom na sam xml fajl u exploreru i odem u propertis dobijem General i tu tih polja za dozvolu pristupa nema.Kada kliknem na propertis foldera u kome se nalazi xml fajl dobijem Sharing,WEB Sharing,Customize i General.Sve u svemu nemam pojma gdew su ta polja koje treba da cekiram.Pomozi ako mozes.
05-08-2007 07:41 PM
Find all posts by this user Quote this message in a reply
Puž Offline
Redoviti posjetitelj
**

Posts: 132
Joined: Mar 2007
Reputation: 25
Post: #6
RE: Upomoc zasto mi ovaj ASPNET kod ne radi?
   
05-08-2007 08:46 PM
Find all posts by this user Quote this message in a reply
vselak Offline
Novi korisnik
*

Posts: 7
Joined: Jul 2007
Reputation: -1
Post: #7
RE: Upomoc zasto mi ovaj ASPNET kod ne radi?
Pazi care,verujem ti ja samo mi nije jasno kako ja to nemam.Mora da je neko podesavanje u vezi foldera,sad cu da bunarim.Imam General ,ali ne i Security.Sta li je to???Poludecu.
05-08-2007 09:27 PM
Find all posts by this user Quote this message in a reply
Puž Offline
Redoviti posjetitelj
**

Posts: 132
Joined: Mar 2007
Reputation: 25
Post: #8
RE: Upomoc zasto mi ovaj ASPNET kod ne radi?
Budući da nemreš vidjet security tab pretpostavljam da imaš Windows Xp Home edition. Na home editionu security tab možeš vidjet samo iz safe moda. Odi u safe mode i tam podesi security.

Ak ti se neda tak radit možeš skinut ovo http://support.microsoft.com/?kbid=245216 pa buš vidil security tab (bar brijem... ovo sam zguglo i našo. piše da radi Hmmm)

P.S. Ak se baviš informatikom preporučal bi ti da nabaviš XP Proff. Puno je praktičniji za informatičke poslove
05-08-2007 09:51 PM
Find all posts by this user Quote this message in a reply
vselak Offline
Novi korisnik
*

Posts: 7
Joined: Jul 2007
Reputation: -1
Post: #9
RE: Upomoc zasto mi ovaj ASPNET kod ne radi?
Hvala ti puno brate,uradio sam ga iz safe moda-a.Proradilo i to sa onom klasom Global.Nikad ne bi provalio,de si ovo samo nasao,da kod Homa XP-a se ovo vidi u Safe-u.Jebote nikad ovo ne bih nasao.Svaka cast!!!Izgubio sam dane i dane nervirajuci se.I to sam dozvolio pristup ovom xml-fajlu (everyone).Sta ti je znanje,de ovo ima da se Procita u onim knjigama o Operativnim sistemiba Bible i to.U svakom slucaju hvala.Sad kad mi je ovo proradilo,nekako cu sam.I zakuni se u ovim knjigama o Web programiranju nista o ovome da kazu.Valjda je najvaznije da proradi osnovna aplikacija lako ces ti posle da nadogradjujes kad shvatis osnovnu caku. Cao ,jos jednom Hvala!
Imam jos samo jedno pitanje za tebe:
Znas li da mi kazes zasto kada u Default.aspx.cs ubacim kod:
labelEntryDetails.Text=entry.Timestamp.ToString("dddd") + " , " + entry.Timestamp.ToLongDateString() + " - " + entry.Details;

Mi u explorer-u ispisuje :Monday , Monday, August 06, 2007
U mesto: Monday,August 06,2007
Normalno uz gore navedeni kod ide prateci u Global.asax.cs:
newEntry.Timestamp= new FileInfo(filepath).LastWriteTime;

Mada ti ne koristis Global,ali to nije bitno.


Opet sam morao spajati postove. Vec si iznad napravio istu gresku - bio si upozoren. Ide rep [ - ]
-by hurmash1ca
05-08-2007 10:42 PM
Find all posts by this user Quote this message in a reply
Puž Offline
Redoviti posjetitelj
**

Posts: 132
Joined: Mar 2007
Reputation: 25
Post: #10
RE: Upomoc zasto mi ovaj ASPNET kod ne radi?
Pa zato kaj ti
"entry.Timestamp.ToString("dddd")" veli "Monday", a
"entry.Timestamp.ToLongDateString()" veli "Monday, August 06, 2007"

Tu si ga opet bezveze zakomplicirao. ToLongDateString nemoj koristit, šugav je skroz.

Ak bi htio dobit datum u formatu "Monday,August 06,2007", ja bi na tvom mjestu to ovak riješio:

gore dodaj
Code:
using System.Globalization;
I ovak riješi prikaz datuma:
Code:
            CultureInfo ci;
            ci = new CultureInfo("hr-HR"); //Hrvatski jezik (dobijemo datum na hrvatskom jeziku)

            labelEntryDetails.Text = entry.Timestamp.ToString("dddd, dd MMMM yyyy", ci);
08-08-2007 03:54 PM
Find all posts by this user Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)