|
w3 schools.com
Q. Hey man! have you sorted out the finite soup machine?
A. Why yes, it's celery or tomato.
|
|
|
|
|
|
|
First at all, I would like to thank you for all your posts, I am new into ASP.NET Web API, and your posts are really helpful to me.
I would like to know if you are planning to post something about Securing Web API from clients other than Web browsers, for example manage the login and authentication between requests from a Mobile client.
Thank you again for your help !!
|
|
|
|
|
This is not a valid question. There are hundreds of people visiting these forums, so it is impossible to know who will post what. If you are interested in learning more about any subject then go to the Articles section[^].
Use the best guess
|
|
|
|
|
Hi All,
Suppose I send a request to the server and I get an error, aside from using trace.axd and the debugger to determine the cause of the error, what else can I do? Thanks in advance for your reply.
|
|
|
|
|
|
Hi David, thanks for replying. Most of the topics in the website you've provided talked about using a third party tool to log errors and some talked about writing to the Event log. I was hoping to find out a way to view errors using Visual Studio or something that shipped with the Windows.
|
|
|
|
|
The error should appear in the IIS Log file. The default place for the log file is : C:\Windows\System32\LogFiles
|
|
|
|
|
Hi,
I wanna to have a webservice in aspnet (C#) that :
select * from tableName (OR call Stored Procedure)
and save the result in Text file and finally zip that and delete that text file !
Thanks in advanced !
|
|
|
|
|
And what is your problem?
Use the best guess
|
|
|
|
|
Hi
Dont know how to start and can webservice do that ?
Do you have any example ?
Thanks in advnaced!
|
|
|
|
|
jojoba2011 wrote: Dont know how to start Then you need to read some books, tutorials etc.
jojoba2011 wrote: can webservice do that ? Do what exactly?
Please think about what problem you are trying to solve and give us some clear information about what is not working.
Use the best guess
|
|
|
|
|
Hi,
Thanks a lot!
I am writting an app (android with C#) and the program is :
it have update button for updating database in mobile.
so i wanna do something that get data from sql server 2008 (in host - Internet ) and update my mobile sqlite database.
thanks in advanced @
|
|
|
|
|
jojoba2011 wrote: so i wanna do something that get data from sql server 2008 Then you need to write some SQL commands to extract the data and format it into whatever output you require. There are many resources, both here in the Articles Section[^] and in the wider internet that Google can find, that will help you.
Use the best guess
|
|
|
|
|
I have an interesting issue; I have been tasked with building a "one size fits all" file upload page. I am using C# and the 4.5 framework, so my options are wide open, but I have one problem in particular...
Part of the requirement involves an old upload page; we already have a page that uses a regular file upload control with a button and it works exactly as expected. Here's what I need to do; the page I need to build needs to access the old page in the background and do the following:
Upload the selected file
Return the message displayed by the old page
So I need to build a page that allows the user to select a file and "upload" it by accessing the older page in the background and pass the file and/or file information to it. I do not have access to the code of the old page, so I have to use the new page to handle all of the work.
So far I have played with code I have found using HttpWebRequest,WebClient and even the .net libraries for cURL with no success. Has anyone tackled something similar in the past? Any suggestions?
______________________
Oh Hamburgers!
|
|
|
|
|
Vodstok wrote: Return the message displayed by the old page
What is the message, why is it so important.
|
|
|
|
|
The new page is being built to integrate two old pages into a new interface, so for end users accustomed to the old functionality, they want to be able to present them with the message(s) that the old one did to minimize the changes in how they see things. Basically, it's out of my hands why, it's in the spec so I have to.
There is a new solution in the works, but for the time being, I am tasked with making a new page that "operates" the old page in the background.
______________________
Oh Hamburgers!
|
|
|
|
|
Richards idea is a good one.
I've used the http in a file upload for ckEditor, and it's pretty slick.
Would like to know if it's works out, keep me up to date.
|
|
|
|
|
Is the old page written in ASP.NET? If so, you'll probably have to issue a GET request first, find the hidden view-state and event validation fields, and include those fields in your POST request.
Once you've got the data you need to send, you'll need to build and send a multipart/form-data request. Unfortunately, there's no built-in way to do that prior to .NET 4.5, but there are quite a few examples floating around for earlier versions. Eg: UploadFileEx: C#'s WebClient.UploadFile with more functionality[^]
If you're using .NET 4.5, you can use the new HttpClient[^] class from the System.Net.Http[^] assembly, combined with the MultipartFormDataContent[^] class.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Excellent, I have definitely been missing that detail, Richard. I will give it a shot and let you know how it works
______________________
Oh Hamburgers!
|
|
|
|
|
Okay, so I have a question; I am doing a get, scraping out the event validation and viewstate to send back, but when I try to post back to the page, I am getting what appears to be a non-posted page on the other end.
Since I can't seem to reuse the original request, the page I get has different viewstate information, so I'm not getting the post I hoped (I think that is what is happening anyway). I am definitely hitting the page; I am doing a Response.Write for the returned content and it is definitely loading the correct page in the background.
I seem to be back at square one (albeit using the baked-in features of 4.5, which is nice ). So I am definitely calling the right page, but it does not appear to actually post.
Here is the code I am using:
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(@"http://localhost:51749/Default.aspx");
request.Method = "GET";
request.ContentType = "application/x-www-form-urlencoded";
HttpWebResponse resp = (HttpWebResponse)request.GetResponse();
string respString = string.Empty;
using (Stream strm = resp.GetResponseStream())
{
using (StreamReader sr = new StreamReader(strm))
{
respString = sr.ReadToEnd();
}
}
request = (HttpWebRequest)HttpWebRequest.Create(@"http://localhost:51749/Default.aspx");
List<string> controls = respString.Split('\n').Select(o => o.Replace("\r", string.Empty).Trim()).Where(o => o.StartsWith("<input") && o.IndexOf("hidden") > -1).ToList();
request.Method = "POST";
request.ContentType = "multipart/form-data";
using (HttpClient client = new HttpClient())
{
using (MultipartFormDataContent content = new MultipartFormDataContent())
{
var values = new[]
{
new KeyValuePair<string, string>("txtFile", "BALHHHHH"),
new KeyValuePair<string, string>("fu1", fileName),
}.ToList();
foreach (string cont in controls)
{
List<string> attributes = cont.Split(' ').Where(o => o.ToLower().StartsWith("id") || o.ToLower().StartsWith("value")).Select(o => o.Replace("\"", string.Empty)).ToList();
string id = attributes.Where(o => o.ToLower().StartsWith("id")).FirstOrDefault().Split('=')[1];
string value = attributes.Where(o => o.ToLower().StartsWith("value")).FirstOrDefault().Split('=')[1];
values.Add(new KeyValuePair<string, string>(id, value));
}
foreach (KeyValuePair<string, string> keyValuePair in values)
{
content.Add(new StringContent(keyValuePair.Value), keyValuePair.Key);
}
ByteArrayContent fileContent = new ByteArrayContent(File.ReadAllBytes(fileName));
fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
{
FileName = Path.GetFileName(fileName)
};
content.Add(fileContent);
string requestUri = "http://localhost:51749/Default.aspx";
HttpResponseMessage result = client.PostAsync(requestUri, content).Result;
using (Stream res = await result.Content.ReadAsStreamAsync())
{
byte[] bres = new byte[res.Length];
res.Read(bres, 0, bres.Length);
Response.Write(Encoding.ASCII.GetString(bres));
}
}
}
I think at this point any suggestion would be a good one. I was using older techniques before and achieving the same thing, and Richard's suggestion seems to be the first thing I have encountered that offered a solution as to why what I was doing before wasn't working, so I suspect something in here is to blame.
______________________
Oh Hamburgers!
|
|
|
|
|
Based on a quick test I did last night, I came to the conclusion that the Name of each part needs to be enclosed in quotes:
foreach (KeyValuePair<string, string> keyValuePair in values)
{
content.Add(new StringContent(keyValuePair.Value), "\"" + keyValuePair.Key + "\"");
}
Without this, ASP.NET doesn't think there's a form present.
(I'm not sure if this is a bug in ASP.NET, a bug in the HttpClient implementation, or a misunderstanding on my part.)
You'll need to specify the name for the file content, which should be equal to the name of the FileUpload control on the target page.
I also found that if the FileName isn't enclosed in quotes, ASP.NET request validation rejects the request:
ByteArrayContent fileContent = new ByteArrayContent(File.ReadAllBytes(fileName));
content.Add(fileContent, "\"nameOfTheFileUpload\"", "\"" + Path.GetFileName(fileName) + "\"");
You're missing an await on the client.PostAsync line, but I presume that's just a typo.
You can also replace the ReadAsStream + Read + Encoding.ASCII.GetString block with a simple await response.Content.ReadAsStringAsync() call.
If all else fails, you can always trace the request with Fiddler[^].
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Most excellent, I am not quite there yet, but considering all of the annoying viewstate errors I am now getting (I appear to need the same machine key for both test sites) I am definitely getting farther than I was. I will update as soon as I get it figured out. Thank you again! This has been a huge help.
______________________
Oh Hamburgers!
|
|
|
|
|
The plot thickens. The page I will eventually have to call is written in JSP, which is of no immediate concern since the basic idea behind this requirement doesn't change, but here's where it gets interesting; the page I am calling uses JavaScript to set the cookies, and the page login immediately fails unless it's executed.
So I'm not only not back to square one, it's not even on the horizon right now. Gotta love legacy products...
______________________
Oh Hamburgers!
|
|
|
|