Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

HttpContext for Asp.net

Posted on 2011-02-15
2
Medium Priority
?
629 Views
Last Modified: 2012-05-11
Hey !

These lines of code are written in global.asax file. I want to confirm what would these lines of code do:

HttpContext context = HttpContext.Current;
string path1 = context.Request.Path.ToLower();
string path2 = Server.MapPath(originalpath);

would path1 have the URL requested each time ? And will path2 have physical path of the resource on server ?

Thanks.
0
Comment
Question by:pratz09
2 Comments
 
LVL 30

Accepted Solution

by:
Brad Howe earned 2000 total points
ID: 34900724
Hi,
That is correct.

For example say my url is
http://www.mydomain.com/subfolder/Default.aspx

HttpContext context = HttpContext.Current;
//Gets or sets the HttpContext object for the current HTTP request.

string path1 = context.Request.Path.ToLower();
//Take the path /subfolder/Default.aspx and changes the case to Lower /subfolder/default.aspx

string path2 = Server.MapPath(path1);
//Take the path /subfolder/Default.aspx and gets the server file location. I just used path1 since originalpath is a variable.
//The results are  c:\inetpub\WebSite1\default.aspx

And yes, those are the vaules
Cheers,
Hades666
0
 

Author Comment

by:pratz09
ID: 34900784
Thanks man.

One more quick question:

I have written

context.RewritePath(landingpage, context.Request.PathInfo, string.Format("page={0}", pagename));

for (int j = 0; j < parentpages.Count; j++)
                    {
                        //some statements
                        }

                        else
                           
                           if (originalpath.Contains("/news/") || originalpath.Contains("/careers/") || originalpath.Contains("/product-catalog/"))
                            {
                               //some statements
                            }

                    }


Since it is a rewrite path statement, will this for loop be executed ? Like, the flow will go to the page where rewrite path has directed it, or will this for loop be executed first and only then it will go to the intended page.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

877 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question