Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

HttpContext for Asp.net

Posted on 2011-02-15
2
Medium Priority
?
624 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
[X]
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
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

730 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