Illegal characters in path asp.net and utf - asp.net

i want get content of web page but when try to access it show this error
"Illegal characters in path"
my question is how i solve it and there is a better way to get content of a page
now i get content with windows application and webbrowser and have no error but cant do in asp
my code
Dim client As New Net.WebClient
TextBox1.Text = client.DownloadString("www.url.com/")
and content of page is
20141105#5058.00#4850.00#4997.00#4870.00#4920.00#4880.00#13553984180.00#2712255#495;
if i change url to http://www.url.com/ the problem solve but character not support like
`‹�طG[T�ے-تAہ0ءI±°M/ùے«Z✖پ$¼×ى(م´;اy­iص)—½؛‚C%%û`
and i add this code but nor work
client.Encoding = Encoding.UTF8

You should include http:// along with the URL to execute the query(TextBox1.Text = client.DownloadString("www.url.com/")) properly, so your code will be like the following:
Dim client As New Net.WebClient
TextBox1.Text = client.DownloadString("http://url.com/")

Related

What is this redirection called and how can it be setup for an ASP based site?

Does this redirection method have a specific name, and how do I set it up for an ASP based site?
http://www.example.com/?URL=www.redirecteddomain.com
Ok, in that case, it not really the web server, but simply your code that can do this.
so, if you web page was:
http://localhost/MyJumpPage.aspx?URL=www.google.com
So, in your code, all you have to do is grab that 1st parameter, and then run code to jump/navigate to that page.
EG:
string strURL = "";
strURL = Request.QueryString("URL");
Response.Redirect("http://" + strURL);
So, the code behind a button, or even on page load can simply pull the query value from the url string, and then jump to that URL.

Access request after upload (ASP classic)

So, as I figured out, when I have a form with enctype="multipart/form-data" and I upload a file, I can no longer access the object request. The following error is shown:
Cannot use the generic Request collection after calling BinaryRead.
After checking some resources, I stumpled upon a statement, which says: "This is by design". Well, okay, not here to judge about design-decisions.
To give you a quick overview, let me walk you through the code:
if request("todo") = "add" then
Set Form = New ASPForm
category = request("category")
title = request("title")
if len(Form("upload_file").FileName) > 0 then
filename = Form("upload_file").FileName
DestinationPath = Server.mapPath("personal/allrounder/dokumente/")
Form.Files.Save DestinationPath
end if
end if
Nothing too special here so far. Later however, when I try to access my request object, the error mentioned above occures:
<% if request("todo") = "new" then %>
...
My question now, how to get rid of it or fix this. I don't want to open the upload in a popup if there is another way around. This is the only solution I could think off.
Perfectly would be an object, which checks Form and request. Alternatively maybe a check at the top of the file, which object I have to use?
Thanks for any suggestions.
There used to be a very popular ASP class/component that solved ASP file uploads. The site for that component has been taken down, but the code is mirrored here:
https://github.com/romuloalves/free-asp-upload
You can include this ASP page on your own page, and on your page instantiate the class to get access to the files in your form, but also to the form variables. Here is a piece of example code (Upload.Form accesses the form fields):
Dim uploadsDir : uploadsDir = server.mapPath(".") ' whatever you want
Dim Upload, ks, fileKey, mailto
Set Upload = New FreeASPUpload
call Upload.Save(uploadsDir)
ks = Upload.UploadedFiles.keys
for each fileKey in ks
Response.write(fileKey & " : " & Upload.UploadedFiles(fileKey).FileName & "<br/>")
next
mailto = Upload.form("mailTo")
Set Upload = Nothing
If you want to stick to your own implementation, you can probably figure out how to get to the form variables in a multipart/form-data encoded data stream by having a look at the code they use to do so.

get a website data and display on my web page

I am Trying to display a website portion on my web page.and for this i dnt want to use iframe.But any other idea which can get data from a website and then display it on my web page like.
this is website
http://www.sugaronline.com/
and want to display this portion on m y web page
http://i.stack.imgur.com/CVsrh.jpg
Please any one tell me is there any way to do this except using iframe?
Update
Shared Function GetHtmlPage(ByVal strURL As String) As String
Dim strResult As String
Dim objResponse As WebResponse
Dim objRequest As WebRequest = HttpWebRequest.Create(strURL)
objResponse = objRequest.GetResponse()
Using sr As New StreamReader(objResponse.GetResponseStream())
strResult = sr.ReadToEnd()
sr.Close()
End Using
Return strResult
End Function
Dim responses As String = GetHtmlPage(theurl)
Refer existing posts
Using HTTPWebRequest in ASP.NET VB
or simply Google this
If you are using PHP, try using CURL, it is a server side request which fetches the data from the target site and then you can embed it in your page.
On the other hand, if you are using .Net, you can use httpwebrequest to do the same.
In short, you will have to make a server side request from your server to the target website to fetch the data and you can embed that data on your page as if it has come from your website.
Please check out this post
How to use httpwebrequest to pull image from website to local file
Here all you need to do is
when you have the image bytes ready, you need to write those bytes to response but before that, you will have to send proper headers to let the browser understand that you are now going to send the image.

Link to a different page in asp.net

I have the following code which should go to a particular company page from the request page. In the website folder Company page is under a folder called Companies and the request page is under Requests folder.
Dim strUrl As String = "/Companies/Details.aspx?Company_ID=" & .Company_id
litlCompany.Text = "" & .Company.Name & ""
The Url should be built as,
http://localhost/Companies/Details.aspx?Company_ID=222
But it comes as,
http://localhost/Requests/Companies/Details.aspx?Company_ID=222
Does anyone knows why?
I'm assuming you are currently on http://localhost/Requests/something.aspx? If so, that's because you forgot the tilde root specifier:
~/Companies/Details.aspx
Which should fix your problem.
You can also try
Page.ResolveClientUrl("~/Companies/Details.aspx?Company_ID=" + Company_id)
By the name of your control it appears that you are using a Literal.
Try changing this to a HyperLink, then you won't need to put the HTML (<a href=...) in the text property, you will be able to use hypCompany.NavigateUrl = strUrl and ASP.Net will generate it for you. This is the neatest way to do it anyhow.
Also add in the tilde to go to the root :-)
E.G.
Dim strUrl As String = "~/Companies/Details.aspx?Company_ID=" & .Company_id
hypCompany.NavigateUrl = strUrl
Am assuming that this link is built in the request.aspx page.
I think the a href is being rendered to the current httpcontext. Have you tried creating the string as :
Dim strUrl As String = "~/Companies/Details.aspx?Company_ID=" & .Company_id
I think this will work if the Companies folder is in the root. The tilda should ensure it looks from the root down.

Emulate Excel Web Query in .net

I need to emulate an Excel Web Query in .net Below is the sample code. I get an Error500 when I attempt to do this in .net, however in Excel it works fine. Any ideas on what I am doing wrong? When I change the URI to a normal website it works fine, and returns the html from the page, which i what i am after. I wonder if the problem lies from the fact that I am trying to return a datatable
Dim oHttpWebRequest As System.Net.HttpWebRequest
Dim oStream As System.IO.Stream
Dim sChunk As String
oHttpWebRequest = (System.Net.HttpWebRequest.Create("http://somesite/foo.jsp"))
Dim oHttpWebResponse As System.Net.WebResponse = oHttpWebRequest.GetResponse()
oStream = oHttpWebResponse.GetResponseStream
sChunk = New System.IO.StreamReader(oStream).ReadToEnd()
oStream.Close()
oHttpWebResponse.Close()
Here is the Query from Excel
WEB
1
http:/somesite/foo.jsp
Selection=DataTable
Formatting=None
PreFormattedTextToColumns=True
ConsecutiveDelimitersAsOne=True
SingleBlockTextImport=False
DisableDateRecognition=False
DisableRedirections=False
Edit
I am getting the error when I getReponse from the server
I found the problem I was having.
I used fiddler to figure out the headers that were being sent via excel and compared those with the headers .net was sending
http://www.fiddler2.com/Fiddler2/version.asp
I had to add the following lines of code to add these two headers in order for it to work
oHttpWebRequest.Headers.Add(HttpRequestHeader.Pragma, "no-cache")
oHttpWebRequest.Headers.Add(HttpRequestHeader.AcceptLanguage, "en-us")

Resources