I have a Blazor app that will be opened via a parent site into a child window. I then want the Blazor app to Post information back to the parent site using this function:
function OpenDocument(URL) {
window.opener.postMessage(URL, "*");
return false
}
This function is triggered by a switch case depending on what file the user clicks on. This is the switch statement code.
string res = "url string" ;
await JSRuntime.InvokeAsync<string>("OpenDocument", Res);
This is the error message that I am getting in Chrome when the javascript function is triggered.
blazor.server.js:formatted:2869 Uncaught (in promise) Error: Cannot send data if the connection is not in the 'Connected' State.
I have looked around for information on this problem and can't seem to find much on it. Any help would be appriciated.
Discovered a work around for anyone that might encounter this problem. Open a blank webpage with a url paramater as the message you want to post and have the blank web page post the message for you. If anyone has any better solutions please post them anyway.
Related
I want to represent a signin in a url(i.e. eclass.aueb.gr) to get the source code of the next page(the portfolio of the user).
What i have now, is the code from documentation...
var response = await "https://eclass.aueb.gr/index.php".PostUrlEncodedAsync(new
{
uname = "name",
pass = "pass"
});
Currently the response is the code of the url itself.
The page is most likely following the PRG pattern (as it should, per best practices), so the fact that the response you are getting is the original page just means you didn't code the redirect part. Do you need to? Not if all you need to do is log in. Are you successfully logged in? Hard to say for certain. response.StatusCode might be "Unauthorized" (401) if it failed (you could test it against invalid credentials), but since you're scraping a site designed for browsers and not automation (like an API), you might have to pick through that big string of HTML you got back and look for error messages. There again, see what happens in a browser when you try to log in with invalid credentials. And remember - Chrome DevTools are your friend, particularly the Network tab in this case.
I have created an Android application with C# on the server side. Following this tutorial, I am using Json web service. Everything is working well, but the only issue is if someone hits www.mydomain.com/Handler.ashx?ANDROID, then all the methods written on server side are downloaded as a text file and the code can be read easily.
What I want to do is that the server should respond only if request is being made from my android application. If someone(hacker/cracker) hits the url, then he should not be able to download the code and should be redirected to some specific page saying unauthorized access prohibited.
Can someone help me with this? Let me know if this question is not clear.
What you can do is to pass a key from your android app for check.
I don't know C# but in PHP it can be something like this -
In your C# file, somewhere near the top of the file, check for a key value sent with a post method. If there is no key passed or wrong key passed, redirect to some other page.
$required_key = "Udsd728392jsakk22";
if(($_POST['key'] == null) || ($_POST['key'] != $required_key)){
//redirect to some other page
header("Location: www.myexampledomain.com/error.php");
}
And from your android app, when you are sending request to the URL, send with a key.
I am making a web browser in C# and have noticed that when I go to steams website and try to login I get message asking for the steam guard code that was sent to my email.
I then go to my email, get the code and enter it but every time I get a message saying "Whoops! Sorry, that isn't quite right.".
I have tried copy and pasting and manually typing in the code to no avail.
Any ideas on what could be going wrong?
Does your browser handle cookies correctly? The moment you submit the code, the steam application creates a cookie. Maybe your browser rejects the cookie thus causing the error.
I have two ASP.NET MVC web apps running on the same server. One of them is a web service that returns an error message in plain text if an exception occurs. However, right now, some clients that call the web service don't receive the error message; instead, they simply receive "Bad Request" in HTML.
The second web app (on the same server as the first) can call a URL handled by the first one and, right now, correctly receives the error message in plain text. However, I have tried calling that URL other ways, and all of them have resulted in receiving "Bad Request":
Pasting the URL into Chrome on my computer
Pasting the URL into IE on the server
Calling the URL from a web app on a different computer from the server
This error does not occur locally. When I run the 2 web apps on my computer, I receive the error message in plain text from both the second web app and from calling the local URL from Chrome.
I have narrowed down the offending line of code to the first line of the following ActionResult snippet:
Response.StatusCode = (int)HttpStatusCode.BadRequest;
return Content(errorMessage, ContentTypes.PlainText);
Removing the first line appears to fix the problem; however, that also eliminates the ability for me to use a descriptive status code. It appears to me that after the ActionResult is returned the response is being intercepted if either (a) the client is on a different computer or (b) the client is a web browser. So I guess I have a 2-part question:
Is there a reason why .NET or IIS would intercept and change a response depending on the client type or location?
Is there an easy way to view the response at any point between this code and when it's dispatched to the client?
Thanks!
Update: I changed the web app to use HttpResponseException. Now I am getting the following YSOD exception:
Processing of the HTTP request resulted in an exception. Please see
the HTTP response returned by the 'Response' property of this
exception for details.
Using MVC version 5, Visual Studio 2013. The code for the ActionResult looks like this:
MyImage image = new MyImage(parameters);
if (image.Errors.Any())
{
throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest) { Content = new StringContent(image.Error) });
}
return File(image.AsJpeg(), ContentTypes.Jpeg);
Anyone have an idea how to bypass this unhelpful response?
Update 2: The issue turned out to be that the error message was being suppressed because of the Web.config setting system.webServer > httpErrors > errorMode which has a default value of "DetailedLocalOnly" and seems to be invoked in some cases for a reason I don't know (although this question may start to shed some light). Once I changed it to this, it worked as I expected:
<httpErrors errorMode="Detailed" />
I understand why they suppress error messages by default on remote machines, but this was a lot harder to track down than I would have thought. Anyway, I hope this is helpful to someone in the future.
I can't think of any reason why IIS would care what client was calling a service. My guess is that the client is sending a different request to the server than what you think it is sending. You can verify this by using a program called "Fiddler".
Also, I'd recommend following a pattern that returns a HttpResponseMessage like this when sending back information from a Web API call:
return new HttpResponseMessage(HttpStatusCode.BadRequest)
{
ReasonPhrase = message,
Content = new StringContent(string.Format("{0}", exception))
};
When I User Window.Location.reload(true) I am getting the popup message for each and every request. Could any body suggest me how to resolve this Issue?
To display the webpage again, the web browser needs to resend the
information
This is the result of sending data via an HTTP POST (which is most commonly done by submitting a form). You will either need to stop using a POST or perform an intermediary redirect to remove this message.