Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

HttpContext for Asp.net

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

789 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