Solved

HttpContext for Asp.net

Posted on 2011-02-15
2
616 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
Comment Utility
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
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

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…
A Change in PHP Behavior with Session Write Short Circuit (http://php.net/manual/en/book.session.php#116217) (Winter 2014)** With the release of PHP 5.6 the session handler changed in a way that many think should be considered a bug.  See the note …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

763 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

13 Experts available now in Live!

Get 1:1 Help Now