Only thing is, when I post to the server, the name of the host chages.
I can do an if x or y then.... but as usual, want to save code space and incase the name of the server changes, need to do something else.
What I have been searching for, unsuccessfully, is a way to insert the wildcard * into the string... such as...
If myurl = "http://" & * & "pagename.aspx" Then
Well, the * is not declared and can't seem to find how to tell the string doesn't matter the host name.
Suggestions?
Thanks all,
ZathI don't recommend approaching this problem with a wildcard. There is a simpler solution.
Try something along these lines:
Dim requestedUrl As String = System.Web.HttpContext.Current.Request.Path.ToLower()The long first line will give us the requested URL, but without the host and application name.
Select Case requestedUrl
Case "default.aspx"
' settings for homepage
Case "about.aspx"
' settings for about page
Case "contact.aspx"
' settings for contact page
Case Else
' settings for page not found
End Select
So this ignores the host and application name, in the same way your wildcard would have done.
I hope this helps.
Thanks!
That works even better!
After posting the message, I was actually looking for a way to get the host name to input it that way and solve the problem.
Zath
The following is a test page that I use quite often.
It allows me to see various Request and HTTP values.
In situations such as the above, you can look at the results of this test page,
and see whether there are any existing values that will match your needs.
For example, this test page will show you which Request property to use if
your URL testing also takes into account QueryStrings.
Anyway, I thought that the following may help you.
<%@. Page Language="C#" Debug="True" Trace="True" %><html>
<head>
</head>
<body>
<h2>Request Report</h2>
<hr />
<p><asp:Label id="Message" runat="server" /></p>
</body>
</html>
<script runat="server">
public void Page_Load (object sender, EventArgs e)
{
Message.Text += "Page.Request.ApplicationPath: " + Page.Request.ApplicationPath + "<br " + "/>";
Message.Text += "Page.Request.FilePath: " + Page.Request.FilePath + "<br " + "/>";
Message.Text += "Page.Request.Path: " + Page.Request.Path + "<br " + "/>";
Message.Text += "Page.Request.PathInfo: " + Page.Request.PathInfo + "<br " + "/>";
Message.Text += "Page.Request.PhysicalApplicationPath: " + Page.Request.PhysicalApplicationPath + "<br " + "/>";
Message.Text += "Page.Request.PhysicalPath: " + Page.Request.PhysicalPath + "<br " + "/>";
Message.Text += "Page.Request.RawUrl: " + Page.Request.RawUrl + "<br " + "/>";
Message.Text += "Page.Request.UserAgent: " + Page.Request.UserAgent + "<br " + "/>";
Message.Text += "Page.Request.UserHostAddress: " + Page.Request.UserHostAddress + "<br " + "/>";
Message.Text += "Page.Request.UserHostName: " + Page.Request.UserHostName + "<br " + "/>";
Message.Text += "Page.Request.Url.AbsolutePath: " + Page.Request.Url.AbsolutePath + "<br " + "/>";
Message.Text += "Page.Request.Url.Host: " + Page.Request.Url.Host + "<br " + "/>";
Message.Text += "Page.Request.Url.LocalPath: " + Page.Request.Url.LocalPath + "<br " + "/>";
Message.Text += "Page.Request.Url.PathAndQuery: " + Page.Request.Url.PathAndQuery + "<br " + "/>";
Message.Text += "<br " + "/>";Message.Text += "<hr />Request.UrlReferrer<br>";
if (Request.UrlReferrer != null)
{
Uri referrer = Request.UrlReferrer;
Message.Text += "Request.UrlReferrer.AbsolutePath: " + referrer.AbsolutePath + "<br>";
Message.Text += "Request.UrlReferrer.AbsoluteUri: " + referrer.AbsoluteUri + "<br>";
Message.Text += "Request.UrlReferrer.Authority: " + referrer.Authority + "<br>";
Message.Text += "Request.UrlReferrer.Fragment: " + referrer.Fragment + "<br>";
Message.Text += "Request.UrlReferrer.Host: " + referrer.Host + "<br>";
Message.Text += "Request.UrlReferrer.LocalPath: " + referrer.LocalPath + "<br>";
Message.Text += "Request.UrlReferrer.PathAndQuery: " + referrer.PathAndQuery + "<br>";
Message.Text += "Request.UrlReferrer.Query: " + referrer.Query + "<br>";
Message.Text += "Request.UrlReferrer.Scheme: " + referrer.Scheme + "<br>";
Message.Text += "Request.UrlReferrer.UserInfo: " + referrer.UserInfo + "<br>";
Message.Text += "<br " + "/>";
}Message.Text += "<hr />Request.Headers" + "<br " + "/>";
OutputCollection(Request.Headers);Message.Text += "<hr />Request.Browser" + "<br " + "/>";
HttpBrowserCapabilities bc = Request.Browser;
Message.Text += "Type = " + bc.Type + "<br>";
Message.Text += "Name = " + bc.Browser + "<br>";
Message.Text += "Version = " + bc.Version + "<br>";
Message.Text += "Major Version = " + bc.MajorVersion + "<br>";
Message.Text += "Minor Version = " + bc.MinorVersion + "<br>";
Message.Text += "Platform = " + bc.Platform + "<br>";
Message.Text += "Is Beta = " + bc.Beta + "<br>";
Message.Text += "Is Crawler = " + bc.Crawler + "<br>";
Message.Text += "Is AOL = " + bc.AOL + "<br>";
Message.Text += "Is Win16 = " + bc.Win16 + "<br>";
Message.Text += "Is Win32 = " + bc.Win32 + "<br>";
Message.Text += "Supports Frames = " + bc.Frames + "<br>";
Message.Text += "Supports Tables = " + bc.Tables + "<br>";
Message.Text += "Supports Cookies = " + bc.Cookies + "<br>";
Message.Text += "Supports VB Script = " + bc.VBScript + "<br>";
Message.Text += "Supports JavaScript = " + bc.JavaScript + "<br>";
Message.Text += "Supports Java Applets = " + bc.JavaApplets + "<br>";
Message.Text += "Supports ActiveX Controls = " + bc.ActiveXControls + "<br>";
Message.Text += "CDF = " + bc.CDF + "<br>";Message.Text += "<hr />Request.ServerVariables" + "<br " + "/>";
OutputCollection(Request.ServerVariables);}
private void OutputCollection(NameValueCollection coll)
{
int loop1, loop2;
String[] arr1 = coll.AllKeys;
for (loop1 = 0; loop1<arr1.Length; loop1++)
{
Message.Text += "Key: " + arr1[loop1] + "<br " + "/>";
// Get all values under this key.
String[] arr2=coll.GetValues(arr1[loop1]);
for (loop2 = 0; loop2<arr2.Length; loop2++)
{
Message.Text += "Value " + loop2 + ": " + Server.HtmlEncode(arr2[loop2]) + "<br " + "/>" + "<br " + "/>";
}
}
}
</script>
Don't you think usingTrace would be simpler for this?
> Don't you think using Trace would be simpler for this?
The test page does have tracing turned on, so trace information is included on the page.
But Trace alone will not show the value of the Request's properties, or the Request.UrlReferrer's properties.
I know that much of my output is redundant for a page with Trace output. But the idea is tosee how the values in the HTTP headers and the form collection translate into the various properties available in the current Request object.
A simple page like this excuses me from having to remember which of the Request properties include the querystring, and which do not. Even though it was a test page I made when I was new to ASP.NET, I still find it helpful. I simply thought it may help the original poster, too.
Thanks SomeNewKid, that test page does help a LOT!
Yes, it is because I am doing a new user email confirm activate new account page.
The URL will have a querry sting in it for confirmation.
Zath
0 comments:
Post a Comment