Solved

HttpContext for Asp.net

Posted on 2011-02-15
2
617 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 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
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.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

910 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now