Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Exceptional Error

Reply
Thread Tools

Exceptional Error

 
 
mohit
Guest
Posts: n/a
 
      12-20-2005
Hi,
I am creating a web application in Web Matrix on the .NET
framework.
I have two directories :AddUser and FormAuth in a Directory P.

AddUser contains a file AddUser.aspx
FormAuth contains : Default.aspx , Users.xml , Login.aspx

I have the following code :

DataSet ds = new DataSet();

String userFile = "../Users.xml";

FileStream fs = new FileStream(Server.MapPath(userFile),
FileMode.Open,FileAccess.Read);
StreamReader reader = new StreamReader(fs);
ds.ReadXml(reader);
fs.Close();


When I run it it gives the following exception :

[HttpException (0x80004005): Cannot use a leading .. to exit above the
top directory.]
System.Web.Util.UrlPath.Reduce(String path) +581
System.Web.Util.UrlPath.Combine(String basepath, String relative)
+251
System.Web.HttpRequest.MapPath(String virtualPath, String
baseVirtualDir, Boolean allowCrossAppMapping) +192
System.Web.HttpServerUtility.MapPath(String path) +61
ASP.AddUser_aspx.Button1_Click(Object sender, EventArgs e) in F:\DC
Downlaods(complete)\mohitag\MyProject\AddUser\AddU ser.aspx:28
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +83

System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String
eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
+33
System.Web.UI.Page.ProcessRequestMain() +1263

IF YOU HAVE SOME IDEA PLEASE TELL ME AS SOON AS POSSIBLE.

Thank you very much

 
Reply With Quote
 
 
 
 
Kevin Spencer
Guest
Posts: n/a
 
      12-20-2005
Your web server doesn't allow parent paths. You either have to use a
root-relative path, and absolute path, or configure your web server to allow
parent paths.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.

"mohit" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> Hi,
> I am creating a web application in Web Matrix on the .NET
> framework.
> I have two directories :AddUser and FormAuth in a Directory P.
>
> AddUser contains a file AddUser.aspx
> FormAuth contains : Default.aspx , Users.xml , Login.aspx
>
> I have the following code :
>
> DataSet ds = new DataSet();
>
> String userFile = "../Users.xml";
>
> FileStream fs = new FileStream(Server.MapPath(userFile),
> FileMode.Open,FileAccess.Read);
> StreamReader reader = new StreamReader(fs);
> ds.ReadXml(reader);
> fs.Close();
>
>
> When I run it it gives the following exception :
>
> [HttpException (0x80004005): Cannot use a leading .. to exit above the
> top directory.]
> System.Web.Util.UrlPath.Reduce(String path) +581
> System.Web.Util.UrlPath.Combine(String basepath, String relative)
> +251
> System.Web.HttpRequest.MapPath(String virtualPath, String
> baseVirtualDir, Boolean allowCrossAppMapping) +192
> System.Web.HttpServerUtility.MapPath(String path) +61
> ASP.AddUser_aspx.Button1_Click(Object sender, EventArgs e) in F:\DC
> Downlaods(complete)\mohitag\MyProject\AddUser\AddU ser.aspx:28
> System.Web.UI.WebControls.Button.OnClick(EventArgs e) +83
>
> System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String
> eventArgument) +57
> System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
> sourceControl, String eventArgument) +18
> System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
> +33
> System.Web.UI.Page.ProcessRequestMain() +1263
>
> IF YOU HAVE SOME IDEA PLEASE TELL ME AS SOON AS POSSIBLE.
>
> Thank you very much
>



 
Reply With Quote
 
 
 
 
mohit
Guest
Posts: n/a
 
      12-20-2005
Neither the root relative path nor the absolute path are working.
could you please tell me how to configure windows to allow parent
paths.
Thanks

Kevin Spencer wrote:
> Your web server doesn't allow parent paths. You either have to use a
> root-relative path, and absolute path, or configure your web server to allow
> parent paths.
>
> --
> HTH,
>
> Kevin Spencer
> Microsoft MVP
> .Net Developer
> You can lead a fish to a bicycle,
> but it takes a very long time,
> and the bicycle has to *want* to change.
>
> "mohit" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) oups.com...
> > Hi,
> > I am creating a web application in Web Matrix on the .NET
> > framework.
> > I have two directories :AddUser and FormAuth in a Directory P.
> >
> > AddUser contains a file AddUser.aspx
> > FormAuth contains : Default.aspx , Users.xml , Login.aspx
> >
> > I have the following code :
> >
> > DataSet ds = new DataSet();
> >
> > String userFile = "../Users.xml";
> >
> > FileStream fs = new FileStream(Server.MapPath(userFile),
> > FileMode.Open,FileAccess.Read);
> > StreamReader reader = new StreamReader(fs);
> > ds.ReadXml(reader);
> > fs.Close();
> >
> >
> > When I run it it gives the following exception :
> >
> > [HttpException (0x80004005): Cannot use a leading .. to exit above the
> > top directory.]
> > System.Web.Util.UrlPath.Reduce(String path) +581
> > System.Web.Util.UrlPath.Combine(String basepath, String relative)
> > +251
> > System.Web.HttpRequest.MapPath(String virtualPath, String
> > baseVirtualDir, Boolean allowCrossAppMapping) +192
> > System.Web.HttpServerUtility.MapPath(String path) +61
> > ASP.AddUser_aspx.Button1_Click(Object sender, EventArgs e) in F:\DC
> > Downlaods(complete)\mohitag\MyProject\AddUser\AddU ser.aspx:28
> > System.Web.UI.WebControls.Button.OnClick(EventArgs e) +83
> >
> > System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String
> > eventArgument) +57
> > System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
> > sourceControl, String eventArgument) +18
> > System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
> > +33
> > System.Web.UI.Page.ProcessRequestMain() +1263
> >
> > IF YOU HAVE SOME IDEA PLEASE TELL ME AS SOON AS POSSIBLE.
> >
> > Thank you very much
> >


 
Reply With Quote
 
Kevin Spencer
Guest
Posts: n/a
 
      12-20-2005
This is done through the IIS Admin tool, not Windows. Web Site Properties -
Home Directory Tab - Configure Button - Options Tab.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.

"mohit" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> Neither the root relative path nor the absolute path are working.
> could you please tell me how to configure windows to allow parent
> paths.
> Thanks
>
> Kevin Spencer wrote:
>> Your web server doesn't allow parent paths. You either have to use a
>> root-relative path, and absolute path, or configure your web server to
>> allow
>> parent paths.
>>
>> --
>> HTH,
>>
>> Kevin Spencer
>> Microsoft MVP
>> .Net Developer
>> You can lead a fish to a bicycle,
>> but it takes a very long time,
>> and the bicycle has to *want* to change.
>>
>> "mohit" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed) oups.com...
>> > Hi,
>> > I am creating a web application in Web Matrix on the .NET
>> > framework.
>> > I have two directories :AddUser and FormAuth in a Directory P.
>> >
>> > AddUser contains a file AddUser.aspx
>> > FormAuth contains : Default.aspx , Users.xml , Login.aspx
>> >
>> > I have the following code :
>> >
>> > DataSet ds = new DataSet();
>> >
>> > String userFile = "../Users.xml";
>> >
>> > FileStream fs = new FileStream(Server.MapPath(userFile),
>> > FileMode.Open,FileAccess.Read);
>> > StreamReader reader = new StreamReader(fs);
>> > ds.ReadXml(reader);
>> > fs.Close();
>> >
>> >
>> > When I run it it gives the following exception :
>> >
>> > [HttpException (0x80004005): Cannot use a leading .. to exit above the
>> > top directory.]
>> > System.Web.Util.UrlPath.Reduce(String path) +581
>> > System.Web.Util.UrlPath.Combine(String basepath, String relative)
>> > +251
>> > System.Web.HttpRequest.MapPath(String virtualPath, String
>> > baseVirtualDir, Boolean allowCrossAppMapping) +192
>> > System.Web.HttpServerUtility.MapPath(String path) +61
>> > ASP.AddUser_aspx.Button1_Click(Object sender, EventArgs e) in F:\DC
>> > Downlaods(complete)\mohitag\MyProject\AddUser\AddU ser.aspx:28
>> > System.Web.UI.WebControls.Button.OnClick(EventArgs e) +83
>> >
>> > System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String
>> > eventArgument) +57
>> > System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
>> > sourceControl, String eventArgument) +18
>> > System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
>> > +33
>> > System.Web.UI.Page.ProcessRequestMain() +1263
>> >
>> > IF YOU HAVE SOME IDEA PLEASE TELL ME AS SOON AS POSSIBLE.
>> >
>> > Thank you very much
>> >

>



 
Reply With Quote
 
mohit
Guest
Posts: n/a
 
      12-20-2005
I have tried it. I am using IIS in Windows XP.
The errors are as following :

if the code is : String userFile = "../Users.xml";

FileStream fs = new FileStream(Server.MapPath(userFile),
FileMode.Open,FileAccess.Read);


Error is :Exception Details: System.Web.HttpException: Cannot use a
leading .. to exit above the top directory.

If the code is : String userFile = "FormsAuth/Users.xml"; or
"/FormsAuth/Users.xml"

FileStream fs = new FileStream(Server.MapPath(userFile),
FileMode.Open,FileAccess.Read);


Error :Exception Details: System.IO.DirectoryNotFoundException: Could
not find a part of the path "F:\DC
Downlaods(complete)\mohitag\MyProject\AddUser\Form sAuth\Users.xml".

If the code is: String userFile = "F:\DC
Downlaods(complete)\mohitag\MyProject\FormsAuth\Us ers.xml";

FileStream fs = new FileStream(Server.MapPath(userFile),
FileMode.Open,FileAccess.Read);


Error : Compiler Error Message: CS1009: Unrecognized escape sequence

Thank you very much.

Kevin Spencer wrote:
> This is done through the IIS Admin tool, not Windows. Web Site Properties -
> Home Directory Tab - Configure Button - Options Tab.
>
> --
> HTH,
>
> Kevin Spencer
> Microsoft MVP
> .Net Developer
> You can lead a fish to a bicycle,
> but it takes a very long time,
> and the bicycle has to *want* to change.
>
> "mohit" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) oups.com...
> > Neither the root relative path nor the absolute path are working.
> > could you please tell me how to configure windows to allow parent
> > paths.
> > Thanks
> >
> > Kevin Spencer wrote:
> >> Your web server doesn't allow parent paths. You either have to use a
> >> root-relative path, and absolute path, or configure your web server to
> >> allow
> >> parent paths.
> >>
> >> --
> >> HTH,
> >>
> >> Kevin Spencer
> >> Microsoft MVP
> >> .Net Developer
> >> You can lead a fish to a bicycle,
> >> but it takes a very long time,
> >> and the bicycle has to *want* to change.
> >>
> >> "mohit" <(E-Mail Removed)> wrote in message
> >> news:(E-Mail Removed) oups.com...
> >> > Hi,
> >> > I am creating a web application in Web Matrix on the .NET
> >> > framework.
> >> > I have two directories :AddUser and FormAuth in a Directory P.
> >> >
> >> > AddUser contains a file AddUser.aspx
> >> > FormAuth contains : Default.aspx , Users.xml , Login.aspx
> >> >
> >> > I have the following code :
> >> >
> >> > DataSet ds = new DataSet();
> >> >
> >> > String userFile = "../Users.xml";
> >> >
> >> > FileStream fs = new FileStream(Server.MapPath(userFile),
> >> > FileMode.Open,FileAccess.Read);
> >> > StreamReader reader = new StreamReader(fs);
> >> > ds.ReadXml(reader);
> >> > fs.Close();
> >> >
> >> >
> >> > When I run it it gives the following exception :
> >> >
> >> > [HttpException (0x80004005): Cannot use a leading .. to exit above the
> >> > top directory.]
> >> > System.Web.Util.UrlPath.Reduce(String path) +581
> >> > System.Web.Util.UrlPath.Combine(String basepath, String relative)
> >> > +251
> >> > System.Web.HttpRequest.MapPath(String virtualPath, String
> >> > baseVirtualDir, Boolean allowCrossAppMapping) +192
> >> > System.Web.HttpServerUtility.MapPath(String path) +61
> >> > ASP.AddUser_aspx.Button1_Click(Object sender, EventArgs e) in F:\DC
> >> > Downlaods(complete)\mohitag\MyProject\AddUser\AddU ser.aspx:28
> >> > System.Web.UI.WebControls.Button.OnClick(EventArgs e) +83
> >> >
> >> > System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String
> >> > eventArgument) +57
> >> > System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
> >> > sourceControl, String eventArgument) +18
> >> > System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
> >> > +33
> >> > System.Web.UI.Page.ProcessRequestMain() +1263
> >> >
> >> > IF YOU HAVE SOME IDEA PLEASE TELL ME AS SOON AS POSSIBLE.
> >> >
> >> > Thank you very much
> >> >

> >


 
Reply With Quote
 
Kevin Spencer
Guest
Posts: n/a
 
      12-21-2005
You have 4 distinctly different problems here:

(1)
> String userFile = "../Users.xml";
>
> FileStream fs = new FileStream(Server.MapPath(userFile),
> FileMode.Open,FileAccess.Read);


> Error is :Exception Details: System.Web.HttpException: Cannot use a
> leading .. to exit above the top directory.


This would indicate that the current HttpContext of the Page is in the root
(top) directory of the app. The ".." indicates a directory above that one,
which is below the top directory, and therefore outside the ASP.Net app.
This is a security feature of ASP.Net. You can use a root-relative path
instead, such as: "/Users.xml"

(2)
> String userFile = "FormsAuth/Users.xml"; or
> "/FormsAuth/Users.xml"
>
> FileStream fs = new FileStream(Server.MapPath(userFile),


> Error :Exception Details: System.IO.DirectoryNotFoundException: Could
> not find a part of the path "F:\DC
> Downlaods(complete)\mohitag\MyProject\AddUser\Form sAuth\Users.xml".


The path that is indicated in the error message doesn't exist.

(3)
String userFile = "F:\DC
> Downlaods(complete)\mohitag\MyProject\FormsAuth\Us ers.xml";
>
> FileStream fs = new FileStream(Server.MapPath(userFile),
> FileMode.Open,FileAccess.Read);


> Error : Compiler Error Message: CS1009: Unrecognized escape sequence


The "\" character in C# is an escape sequence. You have to escape it with
another "\" character (as in "\\" to represent a "\" character in a string.

(4)
You're programming by guesswork. This is the biggest problem of all. It will
cost you beaucoups time. Do you have the Microsoft .Net SDK? You can
download it for free from:

http://msdn.microsoft.com/netframewo...s/default.aspx

This page has links to the Framework SDK for both 1.1 and 2.0 framework
versions.

You'll save yourself a lot of time by using it. Ever since the first version
of the Framework was released, I've spent about an hour a day on average
reading in it.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.


"mohit" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
>I have tried it. I am using IIS in Windows XP.
> The errors are as following :
>
> if the code is : String userFile = "../Users.xml";
>
> FileStream fs = new FileStream(Server.MapPath(userFile),
> FileMode.Open,FileAccess.Read);
>
>
> Error is :Exception Details: System.Web.HttpException: Cannot use a
> leading .. to exit above the top directory.
>
> If the code is : String userFile = "FormsAuth/Users.xml"; or
> "/FormsAuth/Users.xml"
>
> FileStream fs = new FileStream(Server.MapPath(userFile),
>
>
> Error :Exception Details: System.IO.DirectoryNotFoundException: Could
> not find a part of the path "F:\DC
> Downlaods(complete)\mohitag\MyProject\AddUser\Form sAuth\Users.xml".
>
> If the code is: String userFile = "F:\DC
> Downlaods(complete)\mohitag\MyProject\FormsAuth\Us ers.xml";
>
> FileStream fs = new FileStream(Server.MapPath(userFile),
> FileMode.Open,FileAccess.Read);
>
>
> Error : Compiler Error Message: CS1009: Unrecognized escape sequence
>
> Thank you very much.
>
> Kevin Spencer wrote:
>> This is done through the IIS Admin tool, not Windows. Web Site
>> Properties -
>> Home Directory Tab - Configure Button - Options Tab.
>>
>> --
>> HTH,
>>
>> Kevin Spencer
>> Microsoft MVP
>> .Net Developer
>> You can lead a fish to a bicycle,
>> but it takes a very long time,
>> and the bicycle has to *want* to change.
>>
>> "mohit" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed) oups.com...
>> > Neither the root relative path nor the absolute path are working.
>> > could you please tell me how to configure windows to allow parent
>> > paths.
>> > Thanks
>> >
>> > Kevin Spencer wrote:
>> >> Your web server doesn't allow parent paths. You either have to use a
>> >> root-relative path, and absolute path, or configure your web server to
>> >> allow
>> >> parent paths.
>> >>
>> >> --
>> >> HTH,
>> >>
>> >> Kevin Spencer
>> >> Microsoft MVP
>> >> .Net Developer
>> >> You can lead a fish to a bicycle,
>> >> but it takes a very long time,
>> >> and the bicycle has to *want* to change.
>> >>
>> >> "mohit" <(E-Mail Removed)> wrote in message
>> >> news:(E-Mail Removed) oups.com...
>> >> > Hi,
>> >> > I am creating a web application in Web Matrix on the .NET
>> >> > framework.
>> >> > I have two directories :AddUser and FormAuth in a Directory P.
>> >> >
>> >> > AddUser contains a file AddUser.aspx
>> >> > FormAuth contains : Default.aspx , Users.xml , Login.aspx
>> >> >
>> >> > I have the following code :
>> >> >
>> >> > DataSet ds = new DataSet();
>> >> >
>> >> > String userFile = "../Users.xml";
>> >> >
>> >> > FileStream fs = new FileStream(Server.MapPath(userFile),
>> >> > FileMode.Open,FileAccess.Read);
>> >> > StreamReader reader = new StreamReader(fs);
>> >> > ds.ReadXml(reader);
>> >> > fs.Close();
>> >> >
>> >> >
>> >> > When I run it it gives the following exception :
>> >> >
>> >> > [HttpException (0x80004005): Cannot use a leading .. to exit above
>> >> > the
>> >> > top directory.]
>> >> > System.Web.Util.UrlPath.Reduce(String path) +581
>> >> > System.Web.Util.UrlPath.Combine(String basepath, String relative)
>> >> > +251
>> >> > System.Web.HttpRequest.MapPath(String virtualPath, String
>> >> > baseVirtualDir, Boolean allowCrossAppMapping) +192
>> >> > System.Web.HttpServerUtility.MapPath(String path) +61
>> >> > ASP.AddUser_aspx.Button1_Click(Object sender, EventArgs e) in
>> >> > F:\DC
>> >> > Downlaods(complete)\mohitag\MyProject\AddUser\AddU ser.aspx:28
>> >> > System.Web.UI.WebControls.Button.OnClick(EventArgs e) +83
>> >> >
>> >> > System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String
>> >> > eventArgument) +57
>> >> > System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
>> >> > sourceControl, String eventArgument) +18
>> >> > System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection
>> >> > postData)
>> >> > +33
>> >> > System.Web.UI.Page.ProcessRequestMain() +1263
>> >> >
>> >> > IF YOU HAVE SOME IDEA PLEASE TELL ME AS SOON AS POSSIBLE.
>> >> >
>> >> > Thank you very much
>> >> >
>> >

>



 
Reply With Quote
 
mohit
Guest
Posts: n/a
 
      12-21-2005
Following your instructions when I give the absolute path it says that
the path is invalid and asks for virtual path.
When I give the virtual path it says that the path does not exist.I
have even configured my web server for the parent path.
This all is becoming very messy to me.I am unable to understand where
the major mistake is.

Please guide me.

Thank you.

Kevin Spencer wrote:
> You have 4 distinctly different problems here:
>
> (1)
> > String userFile = "../Users.xml";
> >
> > FileStream fs = new FileStream(Server.MapPath(userFile),
> > FileMode.Open,FileAccess.Read);

>
> > Error is :Exception Details: System.Web.HttpException: Cannot use a
> > leading .. to exit above the top directory.

>
> This would indicate that the current HttpContext of the Page is in the root
> (top) directory of the app. The ".." indicates a directory above that one,
> which is below the top directory, and therefore outside the ASP.Net app.
> This is a security feature of ASP.Net. You can use a root-relative path
> instead, such as: "/Users.xml"
>
> (2)
> > String userFile = "FormsAuth/Users.xml"; or
> > "/FormsAuth/Users.xml"
> >
> > FileStream fs = new FileStream(Server.MapPath(userFile),

>
> > Error :Exception Details: System.IO.DirectoryNotFoundException: Could
> > not find a part of the path "F:\DC
> > Downlaods(complete)\mohitag\MyProject\AddUser\Form sAuth\Users.xml".

>
> The path that is indicated in the error message doesn't exist.
>
> (3)
> String userFile = "F:\DC
> > Downlaods(complete)\mohitag\MyProject\FormsAuth\Us ers.xml";
> >
> > FileStream fs = new FileStream(Server.MapPath(userFile),
> > FileMode.Open,FileAccess.Read);

>
> > Error : Compiler Error Message: CS1009: Unrecognized escape sequence

>
> The "\" character in C# is an escape sequence. You have to escape it with
> another "\" character (as in "\\" to represent a "\" character in a string.
>
> (4)
> You're programming by guesswork. This is the biggest problem of all. It will
> cost you beaucoups time. Do you have the Microsoft .Net SDK? You can
> download it for free from:
>
> http://msdn.microsoft.com/netframewo...s/default.aspx
>
> This page has links to the Framework SDK for both 1.1 and 2.0 framework
> versions.
>
> You'll save yourself a lot of time by using it. Ever since the first version
> of the Framework was released, I've spent about an hour a day on average
> reading in it.
>
> --
> HTH,
>
> Kevin Spencer
> Microsoft MVP
> .Net Developer
> You can lead a fish to a bicycle,
> but it takes a very long time,
> and the bicycle has to *want* to change.
>
>
> "mohit" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) ups.com...
> >I have tried it. I am using IIS in Windows XP.
> > The errors are as following :
> >
> > if the code is : String userFile = "../Users.xml";
> >
> > FileStream fs = new FileStream(Server.MapPath(userFile),
> > FileMode.Open,FileAccess.Read);
> >
> >
> > Error is :Exception Details: System.Web.HttpException: Cannot use a
> > leading .. to exit above the top directory.
> >
> > If the code is : String userFile = "FormsAuth/Users.xml"; or
> > "/FormsAuth/Users.xml"
> >
> > FileStream fs = new FileStream(Server.MapPath(userFile),
> >
> >
> > Error :Exception Details: System.IO.DirectoryNotFoundException: Could
> > not find a part of the path "F:\DC
> > Downlaods(complete)\mohitag\MyProject\AddUser\Form sAuth\Users.xml".
> >
> > If the code is: String userFile = "F:\DC
> > Downlaods(complete)\mohitag\MyProject\FormsAuth\Us ers.xml";
> >
> > FileStream fs = new FileStream(Server.MapPath(userFile),
> > FileMode.Open,FileAccess.Read);
> >
> >
> > Error : Compiler Error Message: CS1009: Unrecognized escape sequence
> >
> > Thank you very much.
> >
> > Kevin Spencer wrote:
> >> This is done through the IIS Admin tool, not Windows. Web Site
> >> Properties -
> >> Home Directory Tab - Configure Button - Options Tab.
> >>
> >> --
> >> HTH,
> >>
> >> Kevin Spencer
> >> Microsoft MVP
> >> .Net Developer
> >> You can lead a fish to a bicycle,
> >> but it takes a very long time,
> >> and the bicycle has to *want* to change.
> >>
> >> "mohit" <(E-Mail Removed)> wrote in message
> >> news:(E-Mail Removed) oups.com...
> >> > Neither the root relative path nor the absolute path are working.
> >> > could you please tell me how to configure windows to allow parent
> >> > paths.
> >> > Thanks
> >> >
> >> > Kevin Spencer wrote:
> >> >> Your web server doesn't allow parent paths. You either have to use a
> >> >> root-relative path, and absolute path, or configure your web server to
> >> >> allow
> >> >> parent paths.
> >> >>
> >> >> --
> >> >> HTH,
> >> >>
> >> >> Kevin Spencer
> >> >> Microsoft MVP
> >> >> .Net Developer
> >> >> You can lead a fish to a bicycle,
> >> >> but it takes a very long time,
> >> >> and the bicycle has to *want* to change.
> >> >>
> >> >> "mohit" <(E-Mail Removed)> wrote in message
> >> >> news:(E-Mail Removed) oups.com...
> >> >> > Hi,
> >> >> > I am creating a web application in Web Matrix on the .NET
> >> >> > framework.
> >> >> > I have two directories :AddUser and FormAuth in a Directory P.
> >> >> >
> >> >> > AddUser contains a file AddUser.aspx
> >> >> > FormAuth contains : Default.aspx , Users.xml , Login.aspx
> >> >> >
> >> >> > I have the following code :
> >> >> >
> >> >> > DataSet ds = new DataSet();
> >> >> >
> >> >> > String userFile = "../Users.xml";
> >> >> >
> >> >> > FileStream fs = new FileStream(Server.MapPath(userFile),
> >> >> > FileMode.Open,FileAccess.Read);
> >> >> > StreamReader reader = new StreamReader(fs);
> >> >> > ds.ReadXml(reader);
> >> >> > fs.Close();
> >> >> >
> >> >> >
> >> >> > When I run it it gives the following exception :
> >> >> >
> >> >> > [HttpException (0x80004005): Cannot use a leading .. to exit above
> >> >> > the
> >> >> > top directory.]
> >> >> > System.Web.Util.UrlPath.Reduce(String path) +581
> >> >> > System.Web.Util.UrlPath.Combine(String basepath, String relative)
> >> >> > +251
> >> >> > System.Web.HttpRequest.MapPath(String virtualPath, String
> >> >> > baseVirtualDir, Boolean allowCrossAppMapping) +192
> >> >> > System.Web.HttpServerUtility.MapPath(String path) +61
> >> >> > ASP.AddUser_aspx.Button1_Click(Object sender, EventArgs e) in
> >> >> > F:\DC
> >> >> > Downlaods(complete)\mohitag\MyProject\AddUser\AddU ser.aspx:28
> >> >> > System.Web.UI.WebControls.Button.OnClick(EventArgs e) +83
> >> >> >
> >> >> > System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String
> >> >> > eventArgument) +57
> >> >> > System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
> >> >> > sourceControl, String eventArgument) +18
> >> >> > System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection
> >> >> > postData)
> >> >> > +33
> >> >> > System.Web.UI.Page.ProcessRequestMain() +1263
> >> >> >
> >> >> > IF YOU HAVE SOME IDEA PLEASE TELL ME AS SOON AS POSSIBLE.
> >> >> >
> >> >> > Thank you very much
> >> >> >
> >> >

> >


 
Reply With Quote
 
Kevin Spencer
Guest
Posts: n/a
 
      12-21-2005
It's pretty simple really. The constructior for FileStream requires a file
path to a file. This is not the same as a URL or virtual path. Now, you're
running an ASP.Net application, which works in the context of a web server,
and virtual directories. So, how you get the full file path to the file can
be any number of ways. You can type it into your code as a literal string:

string filePath = @"C:\inetpub\wwwroot\yourAppRoot\somefolder\somefi le.xml";

- or -

string filePath =
"C:\\inetpub\\wwwroot\\yourAppRoot\\somefolder\\so mefile.xml";

You can derive the file path from a web server virtual directory path, as
long as the file is under the root folder of your ASP.Net application:

string filePath = Server.MapPath("/somefolder/somefile.xml"); //
root-relative

string filePath = Server.MapPath("../somefolder/somefile.xml"); // relative
to current Page

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.



"mohit" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
> Following your instructions when I give the absolute path it says that
> the path is invalid and asks for virtual path.
> When I give the virtual path it says that the path does not exist.I
> have even configured my web server for the parent path.
> This all is becoming very messy to me.I am unable to understand where
> the major mistake is.
>
> Please guide me.
>
> Thank you.
>
> Kevin Spencer wrote:
>> You have 4 distinctly different problems here:
>>
>> (1)
>> > String userFile = "../Users.xml";
>> >
>> > FileStream fs = new FileStream(Server.MapPath(userFile),
>> > FileMode.Open,FileAccess.Read);

>>
>> > Error is :Exception Details: System.Web.HttpException: Cannot use a
>> > leading .. to exit above the top directory.

>>
>> This would indicate that the current HttpContext of the Page is in the
>> root
>> (top) directory of the app. The ".." indicates a directory above that
>> one,
>> which is below the top directory, and therefore outside the ASP.Net app.
>> This is a security feature of ASP.Net. You can use a root-relative path
>> instead, such as: "/Users.xml"
>>
>> (2)
>> > String userFile = "FormsAuth/Users.xml"; or
>> > "/FormsAuth/Users.xml"
>> >
>> > FileStream fs = new FileStream(Server.MapPath(userFile),

>>
>> > Error :Exception Details: System.IO.DirectoryNotFoundException: Could
>> > not find a part of the path "F:\DC
>> > Downlaods(complete)\mohitag\MyProject\AddUser\Form sAuth\Users.xml".

>>
>> The path that is indicated in the error message doesn't exist.
>>
>> (3)
>> String userFile = "F:\DC
>> > Downlaods(complete)\mohitag\MyProject\FormsAuth\Us ers.xml";
>> >
>> > FileStream fs = new FileStream(Server.MapPath(userFile),
>> > FileMode.Open,FileAccess.Read);

>>
>> > Error : Compiler Error Message: CS1009: Unrecognized escape sequence

>>
>> The "\" character in C# is an escape sequence. You have to escape it with
>> another "\" character (as in "\\" to represent a "\" character in a
>> string.
>>
>> (4)
>> You're programming by guesswork. This is the biggest problem of all. It
>> will
>> cost you beaucoups time. Do you have the Microsoft .Net SDK? You can
>> download it for free from:
>>
>> http://msdn.microsoft.com/netframewo...s/default.aspx
>>
>> This page has links to the Framework SDK for both 1.1 and 2.0 framework
>> versions.
>>
>> You'll save yourself a lot of time by using it. Ever since the first
>> version
>> of the Framework was released, I've spent about an hour a day on average
>> reading in it.
>>
>> --
>> HTH,
>>
>> Kevin Spencer
>> Microsoft MVP
>> .Net Developer
>> You can lead a fish to a bicycle,
>> but it takes a very long time,
>> and the bicycle has to *want* to change.
>>
>>
>> "mohit" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed) ups.com...
>> >I have tried it. I am using IIS in Windows XP.
>> > The errors are as following :
>> >
>> > if the code is : String userFile = "../Users.xml";
>> >
>> > FileStream fs = new FileStream(Server.MapPath(userFile),
>> > FileMode.Open,FileAccess.Read);
>> >
>> >
>> > Error is :Exception Details: System.Web.HttpException: Cannot use a
>> > leading .. to exit above the top directory.
>> >
>> > If the code is : String userFile = "FormsAuth/Users.xml"; or
>> > "/FormsAuth/Users.xml"
>> >
>> > FileStream fs = new FileStream(Server.MapPath(userFile),
>> >
>> >
>> > Error :Exception Details: System.IO.DirectoryNotFoundException: Could
>> > not find a part of the path "F:\DC
>> > Downlaods(complete)\mohitag\MyProject\AddUser\Form sAuth\Users.xml".
>> >
>> > If the code is: String userFile = "F:\DC
>> > Downlaods(complete)\mohitag\MyProject\FormsAuth\Us ers.xml";
>> >
>> > FileStream fs = new FileStream(Server.MapPath(userFile),
>> > FileMode.Open,FileAccess.Read);
>> >
>> >
>> > Error : Compiler Error Message: CS1009: Unrecognized escape sequence
>> >
>> > Thank you very much.
>> >
>> > Kevin Spencer wrote:
>> >> This is done through the IIS Admin tool, not Windows. Web Site
>> >> Properties -
>> >> Home Directory Tab - Configure Button - Options Tab.
>> >>
>> >> --
>> >> HTH,
>> >>
>> >> Kevin Spencer
>> >> Microsoft MVP
>> >> .Net Developer
>> >> You can lead a fish to a bicycle,
>> >> but it takes a very long time,
>> >> and the bicycle has to *want* to change.
>> >>
>> >> "mohit" <(E-Mail Removed)> wrote in message
>> >> news:(E-Mail Removed) oups.com...
>> >> > Neither the root relative path nor the absolute path are working.
>> >> > could you please tell me how to configure windows to allow parent
>> >> > paths.
>> >> > Thanks
>> >> >
>> >> > Kevin Spencer wrote:
>> >> >> Your web server doesn't allow parent paths. You either have to use
>> >> >> a
>> >> >> root-relative path, and absolute path, or configure your web server
>> >> >> to
>> >> >> allow
>> >> >> parent paths.
>> >> >>
>> >> >> --
>> >> >> HTH,
>> >> >>
>> >> >> Kevin Spencer
>> >> >> Microsoft MVP
>> >> >> .Net Developer
>> >> >> You can lead a fish to a bicycle,
>> >> >> but it takes a very long time,
>> >> >> and the bicycle has to *want* to change.
>> >> >>
>> >> >> "mohit" <(E-Mail Removed)> wrote in message
>> >> >> news:(E-Mail Removed) oups.com...
>> >> >> > Hi,
>> >> >> > I am creating a web application in Web Matrix on the .NET
>> >> >> > framework.
>> >> >> > I have two directories :AddUser and FormAuth in a Directory P.
>> >> >> >
>> >> >> > AddUser contains a file AddUser.aspx
>> >> >> > FormAuth contains : Default.aspx , Users.xml , Login.aspx
>> >> >> >
>> >> >> > I have the following code :
>> >> >> >
>> >> >> > DataSet ds = new DataSet();
>> >> >> >
>> >> >> > String userFile = "../Users.xml";
>> >> >> >
>> >> >> > FileStream fs = new FileStream(Server.MapPath(userFile),
>> >> >> > FileMode.Open,FileAccess.Read);
>> >> >> > StreamReader reader = new StreamReader(fs);
>> >> >> > ds.ReadXml(reader);
>> >> >> > fs.Close();
>> >> >> >
>> >> >> >
>> >> >> > When I run it it gives the following exception :
>> >> >> >
>> >> >> > [HttpException (0x80004005): Cannot use a leading .. to exit
>> >> >> > above
>> >> >> > the
>> >> >> > top directory.]
>> >> >> > System.Web.Util.UrlPath.Reduce(String path) +581
>> >> >> > System.Web.Util.UrlPath.Combine(String basepath, String
>> >> >> > relative)
>> >> >> > +251
>> >> >> > System.Web.HttpRequest.MapPath(String virtualPath, String
>> >> >> > baseVirtualDir, Boolean allowCrossAppMapping) +192
>> >> >> > System.Web.HttpServerUtility.MapPath(String path) +61
>> >> >> > ASP.AddUser_aspx.Button1_Click(Object sender, EventArgs e) in
>> >> >> > F:\DC
>> >> >> > Downlaods(complete)\mohitag\MyProject\AddUser\AddU ser.aspx:28
>> >> >> > System.Web.UI.WebControls.Button.OnClick(EventArgs e) +83
>> >> >> >
>> >> >> > System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String
>> >> >> > eventArgument) +57
>> >> >> > System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
>> >> >> > sourceControl, String eventArgument) +18
>> >> >> > System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection
>> >> >> > postData)
>> >> >> > +33
>> >> >> > System.Web.UI.Page.ProcessRequestMain() +1263
>> >> >> >
>> >> >> > IF YOU HAVE SOME IDEA PLEASE TELL ME AS SOON AS POSSIBLE.
>> >> >> >
>> >> >> > Thank you very much
>> >> >> >
>> >> >
>> >

>



 
Reply With Quote
 
mohit
Guest
Posts: n/a
 
      12-21-2005
I understood it.But I don't understand one thing that why my program is
giving error.
Actually with the constructor FileStream we should give virtual
path.But when I provide
it virtual path it gives the error that the path does not exist.That is
what the major problem is.
I have configured my web server too.

Ideas ??

Thank you.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
VB.NET/ EXCEPTIONAL OPPORTUNITY/ IN OMNI GROUP MCSE 14 03-08-2006 09:46 PM
.NET/ CAREER POSITION/ EXCEPTIONAL OPPORTUNITY/ IN OMNI GROUP MCSE 1 03-07-2006 02:51 PM
.NET/ CAREER POSITION/ EXCEPTIONAL OPPORTUNITY/ IN OMNI GROUP MCSD 0 03-07-2006 01:26 PM
ASP.NET/ EXCEPTIONAL/ NC OMNI GROUP ASP .Net 0 01-10-2006 01:17 AM
Need an "exceptional" public VHDL project Mark Hampton VHDL 0 07-02-2003 05:15 PM



Advertisments