Re: Exceptional Error
- From: "Kevin Spencer" <kevin@xxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 21 Dec 2005 07:01:09 -0500
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\FormsAuth\Users.xml".
The path that is indicated in the error message doesn't exist.
(3)
String userFile = "F:\DC
> Downlaods(complete)\mohitag\MyProject\FormsAuth\Users.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/netframework/downloads/updates/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" <mohitag_agrawal@xxxxxxxxxxx> wrote in message
news:1135116746.166044.74990@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
>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\FormsAuth\Users.xml".
>
> If the code is: String userFile = "F:\DC
> Downlaods(complete)\mohitag\MyProject\FormsAuth\Users.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" <mohitag_agrawal@xxxxxxxxxxx> wrote in message
>> news:1135107737.374312.184290@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
>> > 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" <mohitag_agrawal@xxxxxxxxxxx> wrote in message
>> >> news:1135060181.222243.188940@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
>> >> > 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\AddUser.aspx:28
>> >> > System.Web.UI.WebControls.Button.OnClick(EventArgs e) +83
>> >> >
>> >> > System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
>> >> > eventArgument) +57
>> >> > System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
>> >> > sourceControl, String eventArgument) +18
>> >> > System.Web.UI.Page.RaisePostBackEvent(NameValueCollection
>> >> > postData)
>> >> > +33
>> >> > System.Web.UI.Page.ProcessRequestMain() +1263
>> >> >
>> >> > IF YOU HAVE SOME IDEA PLEASE TELL ME AS SOON AS POSSIBLE.
>> >> >
>> >> > Thank you very much
>> >> >
>> >
>
.
- Follow-Ups:
- Re: Exceptional Error
- From: mohit
- Re: Exceptional Error
- References:
- Exceptional Error
- From: mohit
- Re: Exceptional Error
- From: Kevin Spencer
- Re: Exceptional Error
- From: mohit
- Re: Exceptional Error
- From: Kevin Spencer
- Re: Exceptional Error
- From: mohit
- Exceptional Error
- Prev by Date: Re: want to have <cc:UserControl>some text and tags</cc:UserControl>... How?
- Next by Date: Re: Can't install sqlserver express due previous beta
- Previous by thread: Re: Exceptional Error
- Next by thread: Re: Exceptional Error
- Index(es):