ASPX URL is broken & Streaming WebService - asp.net

I'm attempting to create a streaming webservice, unfortunally i even lack its concept overall. My idea is to have a method which will return to me a string with the value of the URL to the streaming page.
I've tried many different ways to do this, but no one of them worked; I tried using DownloadString, even writting the raw URL, but i always had errors so i found one way to just make it happen:
[WebMethod]
public string WatchMedia(string title)
{
Global.Media = title;
Streaming str = new Streaming(); //Streaming.aspx
return str.GetURL();
}
Okay so, in my aspx.cs i included this:
internal string GetURL()
{
return HttpContext.Current.Request.Url.AbsoluteUri.ToString();
}
Don't really ask me about the 'internal', i'm so tired of trying different ways to get this to work that i just go along with that VS builds for me.
That does give me the URL i thought i wanted, BUT, it doesn't work, why? Because it says, give or take (directly translated):
The request format is not recognized for the unexpectedly terminated URL in /WatchMedia
WatchMedia is the name of my method as seen above.
Now, beside's hoping someone can give me a straight answer as to what ridiculous sin am i hurting my self with here, i'd like to know if this is the way for a streaming webservice to work? I can't seem to find any real information about video streaming webservices over the www, not even Google will tell me!

If you ever have the same problem, just forget creating an object of the aspx page, and get the URL raw, by running the page and copying it, then all you have to do is change the localhost Port, which you can get from HttpContext.

Related

ashx - get all the possible items of QueryString

Looking at this
http://www.dotnetperls.com/ashx
I might have bits of code like this:
string file = context.Request.QueryString["file"];
if (file == "logo")
{
r.WriteFile("Logo1.png");
}
else
{
r.WriteFile("Flower1.png");
}
That should allow me to see different things depending on URL that I enter in a browser, for example:
http://www.dotnetperls.com/?file=logo
http://www.dotnetperls.com/?file=sth_else_eg_flower
The problem I am facing now is how, knowing just http://www.dotnetperls.com/?file can I read what the all the assumed options of the file variable are? In this case it would be "logo" and anything else.
What I have in reality is http://www.somewebstie.com/somefile.ashx?somevariable=. I can Google up the string to get few results (i.e. http://www.somewebstie.com/somefile.ashx?somevariable=abcde or http://www.somewebstie.com/somefile.ashx?somevariable=xyz) thus I know it exists and is somehow searchable. I just would like to know all the other "abcde" and "xyz". If I try just http://www.somewebstie.com/somefile.ashx I get a singe line error saying that I am giving a wrong variable and I cannot see anything important in the source of the site.
What might be important here - I have zero knowledge about web technologies.
You can't get this information. Its all hidden in the code implementation. There is no published format (by default) that will show you all of the available options the code is looking for.

URL filtering , issues with URL

I am working on a URL filtering project . I have a database given to me which contain URLs need to be blocked (eg: a.b.com/d/e).
I get uri and domain from http request. I compare what I get with my database and redirect users without any problem. So far so good.
Problems starts with urls that contains query string and other magics with URL. As an example if user enters a.b.com/d/e?junk. What I get won't match with my database, and users will bypass my filter and they will still be able to go a.b.com/d/e.
I tried some useless actions like slicing everything after special chars like "?,#". But having problems with url like : youtube.com/watch?v=12vh55_1ul8, which becames like youtube.com/watch and blocks all youtube. That solution causes me more problems.
Now I am very confused how to handle this problem. Is there any guide or any library which I can use in C++ ?
Try this code:
string str (get_requsted_uri());
string str2 ("http://getaroundfilters.com/article/889/proxy");
if (str.find(str2) != string::npos) {
block();
} else {
get_and_return_webpage(str);
}

Nesting HTTP GET parameters (request within a request)

I want to call a JSP with GET parameters within the GET parameter of a parent JSP. The URL for this would be http://server/getMap.jsp?lat=30&lon=-90&name=http://server/getName.jsp?lat1=30&lon1=-90
getName.jsp will return a string that goes in the name parameter of getMap.jsp.
I think the problem here is that &lon1=-90 at the end of the URL will be given to getMap.jsp instead of getName.jsp. Is there a way to distinguish which GET parameter goes to which URL?
One idea I had was to encode the second URL (e.g. = -> %3D and & -> %26) but that didn't work out well. My best idea so far is to allow only one parameter in the second URL, comma-delimited. So I'll have http://server/getMap.jsp?lat=30&lon=-90&name=http://server/getName.jsp?params=30,-90 and leave it up to getName.jsp to parse its variables. This way I leave the & alone.
NOTE - I know I can approach this problem from a completely different angle and avoid nested URLs altogether, but I still wonder (for the sake of knowledge!) if this is possible or if anyone has done it...
This has been done a lot, especially with ad serving technologies and URL redirects
But an encoded URL should just work fine. You need to completely encode it tho. A generator can be found here
So this:
http://server/getMap.jsp?lat=30&lon=-90&name=http://server/getName.jsp?lat1=30&lon1=-90
becomes this: http://server/getMap.jsp?lat=30&lon=-90&name=http%3A%2F%2Fserver%2FgetName.jsp%3Flat1%3D30%26lon1%3D-90
I am sure that jsp has a function for this. Look for "urlencode". Your JSP will see the contents of the GET-Variable "name" as the unencoded string: "http://server/getName.jsp?lat1=30&lon1=-90"

.net/iis6 Limitations of the urlMappings in web.config for extensionless url rewriting

I'm investigating a simple url rewriting setup for iis6 / net 2.0 sites.
I've added a . wildcard mapping in IIS that points to the .net executable. I'm also using the urlMappings element in the web.config to add some rewritten urls. I've moved the config outside of the web.config so I can make changes to the list without forcing application restarts, like so:
<urlMappings configSource="config\urlMappings.config">
</urlMappings>
I'd like to allow our content management to add urls to this file so that we can have extensionless friendly urls.
<add url="~/someurl" mappedUrl="index.aspx?page=123" />
This works just fine, but I'm concerned about limitations in the number of entries that I can map in the urlMappings config. I can't seem to find any documentation on this. Has anyone found any limitations?
Thanks.
Looking inside the urlMapping
I see that the mappedUrl
are store on UrlMappingCollection
that come from ConfigurationElementCollection that virtual have no limits.
The number of urls.
I think that virtual there is no limit on how many you can load.
The load time
The load delay is only on the stating the web, then its keep on a static value, and reloaded only when you change the web.config, or restart the app.
The Memory
Well you have a static collection with all that data called on the start of every request. Depends how many data you going to load on web.config.
The search time
The search time, from my research is not done using any hash method, but they compare the strings together one by one, so here maybe we have a small issue.
This is the code with the heavy search for every url
internal string HttpResolveMapping(string path)
{
string mappedUrl = null;
string str2 = UrlPath.MakeVirtualPathAppRelative(path);
UrlMapping mapping = this.UrlMappings[str2];
if (mapping != null)
{
mappedUrl = mapping.MappedUrl;
}
return mappedUrl;
}
here the UrlMapping mapping = this.UrlMappings[str2]; is calling the
protected internal ConfigurationElement BaseGet(object key)
{
foreach (Entry entry in this._items)
{
if ((entry._entryType != EntryType.Removed) && this.CompareKeys(key, entry.GetKey(this)))
{
return entry._value;
}
}
return null;
}
I need to check it a little more, but I think there is an issue on search for the url mapping.
In Real Life
Recently I optimize similar code for database calling. I get down the speed from 500ms to 150ms-200ms on a similar loop that is called 20.000-50.000 times in few seconds.
In your case I do not think that this routing is going to called more than 100-200 times in a page call. (and I say 100 because you redirect all call to asp.net, even the images)
So I think that is really depend for how super fast you won your web to be, but the users of you I do not think that they note the different, and on this point you only going to gain 10-20-30ms faster - and we speak only if you have huge amount of urls (maybe more than 1500 urls).
Also the first page with the content is called, then search from this loop, return the page, then the images follows, so the user is going to see the different only on the first 1-5 calls delay of the page and did not understand the small delay on the images.
The optimization here is only going to be measured on programs and not be understand by the users.
The times here is from my experience on my (slow) computers and is to give only the sense of my experience.
Some more words
I think that urlMapping is a ready to go solution that can help anyone to start with, but if some have the time the knowlege and the resource is worth to fix his own url mapping, make it in his needs and super fast if hes like. For start is good to have urlMapping but if you need some more advanced thinks, then you can update it later when your project go bigger.
I am fan of the speed, every second that wait on the computer is a second from our life.
How ever if it easy for you to use the urlMapping just do it, make the site workable, and then you check it again after some months.

ASP.NET: Get *real* raw URL

In ASP.NET, is there any way to get the real raw URL?
For example, if a user browse to "http://example.com/mypage.aspx/%2F", I would like to be able to get "http://example.com/mypage.aspx/%2F" rather than "http://example.com/mypage.aspx//".
I would of course like a clean way to do it, but I can live with a hacky approach using reflection or accessing obscure properties.
At the moment, I try to use the uri in the Authorization-header (which works), but I cannot rely on that always being there.
EDIT:
What I really want to do is to be able to distinguish between "http://example.com/mypage.aspx/%2F" and "http://example.com/mypage.aspx/%2F%2F".
It looks like ASP.NET first converts "%2F%2F" into "//" and then converts the slashes into a single slash.
So just re-encoding it is not going to work.
I wasn't able to test this because it only works in IIS and not the ASP.NET Development Server that is part of Visual Studio, but try:
Request.ServerVariables[ "HTTP_URL" ]
The following code works for me:
IServiceProvider serviceProvider = (IServiceProvider)HttpContext.Current;
HttpWorkerRequest workerRequest = (HttpWorkerRequest)serviceProvider.GetService(typeof(HttpWorkerRequest));
string realUrl = workerRequest.GetServerVariable("HTTP_URL");
Note that this only works when running on the IIS and not under f.x. ASP.NET Development Server!
Thanks to Lucero for the answer in another thread and Zhaph for pointing me to the thread.
See also:
Get the exact url the user typed into the browser
Server.HtmlEncode(Request.RawUrl);
The raw URL is defined as the part of the URL following the domain information. In the URL string http://www.contoso.com/articles/recent.aspx, the raw URL is /articles/recent.aspx. The raw URL includes the query string, if present.
see also:link text
I can't test here, but this might be what you need:
Request.Url.AbsoluteUri
Request.RawUrl will return the application relative path(including querystring info) while Request.Url will return the complete path(including querystring info).
For more information, see "Making sense of ASP.NET paths".
Well, you could just encode it back to the url-encoded version.
Get the url from the request and urlencode only the query string part and then concatenate them

Resources