In the previous activity, you saw that a URL can include query information.
A C# program can take information supplied by a user and use it to build the URL that will be opened in a browser.
For the FIT weather activity, the important flow is:
user information
↓
C# string value
↓
URL text
↓
browser request
The goal is not to build a complete web application.
It is to trace how one piece of information becomes part of a web request.
Assume the supplied course application has already made a user's location available as text.
Conceptually:
string location = userInput;
The exact control or source that supplies userInput is part of the supplied application.
You do not need to redesign the user interface.
Focus on the value itself.
If the learner entered:
Madison
then the program now has a string representing that input.
A URL can be stored in a string.
For example:
string baseUrl = "https://example.com/search";
A query portion is also text:
?location=
The program can combine the fixed parts with the user-supplied value.
Conceptually:
string url = baseUrl + "?location=" + safeLocation;
In this example:
baseUrl is the fixed destination;?location= establishes the query parameter;safeLocation represents the user value in a form suitable for the URL.The supplied course application determines the exact destination and URL-building code you will use.
String concatenation joins pieces of text.
Consider:
string teamName = "Wildcats";
string message = "Team: " + teamName;
The resulting string is:
Team: Wildcats
A URL can be assembled in the same general way.
Several pieces become one final string.
A useful mental model is:
fixed URL text
+
user-supplied value
=
constructed URL
The user should not need to type the entire web address if the application already knows the destination.
The program can supply the fixed structure and insert the changing information where it belongs.
Suppose one site expects:
?location=Madison
Another might expect a completely different parameter name or path.
The program must use the URL format required by the destination.
The current course application supplies that structure.
Do not rename parameters or invent another destination because it looks more readable.
A location such as:
Green Bay
contains a space.
Raw user text may also contain symbols with special meaning in a URL.
That is why real URL construction needs to represent user input safely.
For this course activity, use the supplied URL-building approach rather than writing your own replacement.
The important reasoning is:
the user's text becomes data inside a structured request.
Before the browser opens, the program has a final URL string.
That string is useful evidence.
Read it and identify:
For example, a completed URL may conceptually resemble:
https://example.com/search?location=Madison
You should be able to explain which portion came from the application and which portion came from the user.
Building the URL does not mean the website has already been contacted.
At this point, the program has created text.
The next step is to ask the operating environment to open that URL in a browser.
Only then does the normal browser request/response process begin.
The key sequence is:
Get user information
↓
Represent it as text
↓
Build the required URL
↓
Pass the URL to the browser-opening step
This activity is about constructing the request destination.
The next activity focuses on what happens when the C# application asks the browser to display it.