I want to pass 3 parameters to ashx file to handle the image, for that i used ImageUrl=ImageHandler.ashx?uid=1&iid=1&pid=1 but the image get not bound..
Help with correct syntax..
You may forget " for the code plus the correct location:
ImageUrl="~/ProjectLocationPathToTheImage/ImageHandler.ashx?uid=1&iid=1&pid=1"
If ImageUrl=ImageHandler.ashx?uid=1&iid=1&pid=1 is a part of your URL, then it appears that ImageUrl=ImageHandler.ashx is a query string parameter. If so, you need to change ?uid= to &uid=. What is the full URL that you are having issues with?
Related
I have a URL say /Registration/GetName.aspx/?language=English
When i click on a Asp.net Button on the same Page and say Response.Redirect("CheckLoginName.aspx");
It gives me a weird URL
/Registration/GetName.aspx/CheckLoginName.aspx
What should i do
Please Help?
You should use "~/" inside your Redirect
So your code will look something like this
Response.Redirect("~/CheckLoginName.aspx");
Hope this helps
You should remove the trailing / before the query string, since it serves no purpose. Your URL should be /Registration/GetName.aspx?language=English. Another option is to have Response.Redirect("../CheckLoginName.aspx"); This should also work.
I think a solution using a relative path is better, since it is location independant. If you move these two files to another URL, there will be no need for code changes.
After reviewing the code below, I noticed that the call to Context.RewritePath is somehow not losing the query string, even though it is being called without a query string. Is there any documentation explaining why the query string is being maintained?
//URL relative path to ashx files is wrong to to path rewriting.
if (Request.Url.LocalPath.EndsWith(".ashx")) {
Context.RewritePath(Request.Url.LocalPath
.Substring(Request.Url.LocalPath.LastIndexOf("/") + 1));
}
Edit: I am not asking how to fix this; the code behaves correctly. I am just asking for documentation of this behavior.
You're essentially doing a Rewrite of the path, and in most cases, the query needs to be maintained to pass to the new Path.
Take for example a new document retrieval page named "getDocumentWithEnhancements.aspx" as opposed to the old "getDocument.aspx". Both need a parameter to be useful, but you want the new one to be used. A RewritePath would do the job, as it takes the query passed to the old, and passes to the new. If you want to show some sort of error page or something, then instead you'd either use a redirect, or whatever page you're rewriting to will just ignore the querystring.
Why would you not want the query to be passed through? What exactly are you using this for? Maybe it's not the right function for what you need.
edit: There's an overloaded function taking 3 parameters, one of which is a querystring, which you could pass in as null to not use the querystring.
i want get extension file of url .
for example get extension http://www.iranfairco.com/download-file/02912bb889cb24.
if extension this file is gif.
EDIT:
for example this url "http://www.online-convert.com/result/d8b423c3cbc05000cc52ce7015873e72"
Please help me how can get extension of this url?
Why does Path.GetExtension not work for you?
EDIT
Ah, so your url doesn't specify the extension you are after. That means anything could be behind it.
Just by inspecting the string value of the url, you can't see what will behind it. Your (second) example point (ultimately) to a .gif file, but it could also have been a .jpg, .doc (or even .exe).
You will need to do a webrequest to see what you get back. Usually you could try a HEAD to get just the headers (and inspect the content type), but I don't think that will work here. Try Fiddler to see what you get back, then you can refine your question.
Check out here:
http://www.java2s.com/Code/CSharp/Network/GetHTTPResponseheaders.htm
You will be interested in the response.ContentType which should give you something like "image/gif" for a gif image
try this
string path = #"http://www.iranfairco.com/download-file/02912bb889cb24.gif";
string e = Path.GetExtension(path );
This URL appears to perhaps be linking to a page which will have a download for a file.
The 02912bb889cb24 is perhaps a database reference to that file.
Therefore without access to any API for this system, I don't think its possible at all to work out the file extension for the file accessed via this URL
You can just split the string on char '.' and get the last string in the returned array..
I want to remove the Querystring part from my Request.UrlReferrer.AbsoluteUri before the Redirect in C#.
For example, if you have got your
Request.UrlReferrer.AbsoluteUri = "http://localhost:8080/english/index_2011.aspx?logout=true"
Now I want to
Response.Redirect(Request.UrlReferrer.AbsoluteUri) without QueryString part (?logout=true")
Please suggest using C#
use Request.UrlReferrer.AbsoluteUri.ToString().Split('?')[0]
This should do the trick for you.
A cleaner way would be
Request.UrlReferrer.GetLeftPart(UriPartial.Path)
Meaning I want everything up to the path. It should return
"http://localhost:8080/english/index_2011.aspx"
Response.Redirect(Request.UrlReferrer.AbsoluteUri.Substring(0,Request.UrlReferrer.AbsoluteUri.IndexOf('?')));
EDIT
In fact, you can actually use:
Response.Redirect(Request.UrlReferrer.AbsolutePath);
Check it out on MSDN.
what c# class method can I use to URL encode a URL string?
In my use case I want to pass a URL string as a URL parameter itself. So like burying a URL within a URL. Without some encoding the "&" and "?" characters in the inner URL can get picked up when the parameters for the outer Url parameters are processed
thanks
HttpUtility.UrlEncode
System.Net.WebUtility.UrlEncode(str)
HttpServerUtility.UrlEncode might be exactly what you are looking for.
Use Server.UrlEncode
You need an instance of the HttpServerUtility class, because the UrlEncode method is not static.
See http://msdn.microsoft.com/en-us/library/system.web.httpserverutility(v=VS.90).aspx
I am operating with .net framework 2.0. But it never shows me "UrlEncode" intelisense when I place dot after httpserverutility. Here are the options I see:
HttpServerUtility.Equals
HttpServerUtility.ReferenceEquals
HttpServerUtility.UrlTokenDecode
HttpServerUtility.UrlTokenEncode
That's it, these are the only options I see. Could I possibly ask for small piece of code as an example to use url encode function?
Thanks,
Linda