String disappears when I use String.Substring - asp.net

I am using ASP.NET to create the website. But on my way, I was told to use string.Substring(int, int) to create a substring when the length increases.
I also searched for a better option here about the character limit in ASP.NET but either they were for ASP.NET Web Forms or they were for C#, but I am using ASP.NET Web Pages.
The code that I am using is this:
#if(message.Length > 80) {
message.Substring(0, 80);
} else {
<text>#message</text>
}
The issue is that, when the character count is under 80 the message is shown to the user, but when it exceeds the limit (above 80) the message is not viewed. However, I have tried to show 3 messages at a time one with a length 10 other with 25 and the last one with 117, the last one was not shown. As it had to pass the first block. The other who passed from else block. They got written down.
I think there is some kind of bug in the block, but I am not able to figure it out. I also want a better suggestion to break the string, where the character limit catches up. I want to break the string where the character limit 80 comes up. Any good idea of how to do this? If the substring is the best then please guide me.

In else part you have written
<text>#message</text>
But this is missing in if block.
Please add this to if block
if(message.Length > 80) {
message= message.Substring(0, 80);
<text>#message</text>
}
else {
<text>#message</text>
}
I hope it will help you.

Related

IIS returning a page in response.responseText

A user attempted to upload a file that was too large (70MB for a single PDF page) and the system errored out. This is correct and expected behavior, however in the response.responseText (in a jQuery AJAX call) instead of just being the message, it was raw text of an entire html page, cut off at a certain point, which I believe coincides with the default style of IIS error pages.
I do not want to increase the limit of the file size to allow the file to come through, but I do wish to make it to where response.responseText just returns the message (effectively, what's between the < title > < /title > tags).
I attempted to set breakpoints in the upload.ashx file to see if I could find where this was happening, but it never gets that far (if it is a normal file, these breakpoints hit). Which is fine, I'm okay with IIS gatekeeping (I imagine if I try to bypass IIS for handling it, the file is going to get uploaded to the server and then rejected. Plus, lose out on just letting IIS configuration handle this), but I don't want to return an entire page if possible.
To my mind, the resolution I see is to see if response.responseText contains DOCTYPE and if so, scrape what is inside the title tag, but I feel like there may be a more by the book way of doing this?
edit: I did see where someone recommended setting existingResponse="PassThrough" on the httpErrors section of web.config, but when I did this the responseText just became blank and it still didn't touch breakpoints so I don't think this is achieving what I'm after.
This probably isn't the best way to handle, but seems to work in this case so just running with it:
changed:
error: function (response) {
alert(response.responseText);
}
to:
error: function (response) {
var titleIndex = response.responseText.indexOf('<title>');
var titleEndIndex = response.responseText.indexOf('</title>');
var message = response.responseText.substr(titleIndex + 7, titleEndIndex - titleIndex - 7);
alert(message);
}
which returns "IIS 10.0 Detailed Error - 413.1 - Request Entity Too Large" in this particular instance.

How do I hold a specific position using Zaber Console Script?

I am trying to write a simple script using Zaber Console.
I basically have to move my robot arm to a certain position (i.e. 43.9mm) hold the position for 10 minutes and go back to the home position.
I found all the command for moving (fast/slow and with a certain acceleration) but I can't undestand how to tell the machine to stay at 43.9mm poistion for 10 minutes.
Any suggestions ?
I am coding in "this language":
if(PortFacade.Port.IsAsciiMode)
{
Conversation.Request("move abs", 881890);
Conversation.PollUntilIdle();
}
else
{
Conversation.Request(Command.MoveAbsolute, 881890);
}
Thanks a lot.
Riccardo
For your reference, if you are coding through the script editor in Zaber Console, we offer a scripting page which covers C#, Javascript, VP, as well as Python. You can find the scripting page here: http://www.zaber.com/wiki/Software/Zaber_Console/Scripting
The language in your script is using C#, and a quick program to execute what you'd like to do can be written like this:
#template(simple)
var device1 = PortFacade.GetConversation(1); // This is assuming your device
// is device 1 in the chain.
// The device list in Zaber Console will let you know the device number.
// Alternatively, you can use the renumber command to change the device number.
device1.Request("move abs 100000"); //the data value for 43.9 mm will vary
// from device to device. The formula would be 43.9[mm]/ Microstep size[mm] = Data value
// The microstep size can be found on the product page at www.Zaber.com, or
// email Contact#Zaber.com
Sleep(5000); //Sleep is in milliseconds
device1.Request("move abs 0");
If you have any questions, please don't hesitate to email Contact#Zaber.com.
Regards,
Albert

Firebase is giving "maxretry" error

We're using Firebase as a backend for our mobile app. Some of our users have sporadically received an error "maxretry" with a transaction writing to a path with single numeric value. We don't have multiple users or connections, nor multiple writes to the same path, as far as I know. What might be causing this?
I have a suspicion that this is caused by using floating point values with many decimal places. This error happened to me locally once and I was able to resolve it by limiting the precision to two decimal places. Can this be it?
-Albert
Edit:
Here's the code that is causing this:
return fireRef.child(fbPath).transaction(function(originalVal) {
return func(originalVal, by_value);
}, _.noop, false)
where in this case the func looks like this:
function(originalVal, val) {
return val + (originalVal || 0);
}
The problem persisted even after limiting precision to 2 decimals (getting maxretry error every once in a while).
It looks like when updating a value using Firebase transactions floating point type should not be used at all.
I moved to using integers and haven't had the problem anymore.

Flex not wanting to use https as specified

I have a small little swf that I'm trying to get to work while the webpage is using https/ssl. I'm passing into the swf the fact that the page is using https and have conditional logic as such:
if ( secure ) {
pollChannel = new AMFChannel('my-secure-polling-amf','https://' + globalDomain + '/flex2gateway/cfamfpollingsecure');
}
else {
pollChannel = new AMFChannel('cf-polling-amf','http://' + globalDomain + '/flex2gateway/cfamfpolling');
}
When the page is http it uses the correct endpoint no problem. When secure == true for whatever reason the browser is reporting its using http://somedomain.local/flex2gateway/cfamfpollingsecure, not https.
Anybody have a clue why??? I don't understand why it would adjust itself like that.
Any help is much appreciated!
Lucky for you I had the exact same mystery issue last week and the fix is extremely simple (once you know where to look, that is; I've been digging through the source code for a while to figure it out):
you just have to use SecureAMFChannel instead of the regular AMFChannel

What is the best way to limit the amount of text that can be entered into a 'textarea'?

What is the best way to limit the amount of text that a user can enter into a 'textarea' field on a web page? The application in question is ASP .NET, but a platform agnostic answer is preferred.
I understand that some amount of javascript is likely needed to get this done as I do not wish to actually perform the 'post' with that amount of data if possible as ASP .NET does have an upper limit to the size of the request that it will service (though I don't know what that is exactly).
So maybe the real question is, what's the best way to do this in javascript that will meet the following criteria:
-Must work equally well for both users simply typing data and copy/paste'ing data in from another source.
-Must be as '508 compliance' friendly as possible.
function limit(element, max_chars)
{
if(element.value.length > max_chars)
element.value = element.value.substr(0, max_chars);
}
As javascript, and...
<textarea onkeyup="javascript:limit(this, 80)"></textarea>
As XHTML. Replace 80 with your desired limit. This is how I do it anyway.
Note that this will prevent the user from typing past the limit in the textbox, however the user could still bypass this using javascript of their own. To make sure, you must also check with your server side language.
use a RegularExpressionValidator Control in ASP.Net to validate number of character along with with usual validation
The most user-friendly idea seems to me a solution like the Twitter-one. Provide a visual indication that the user has crossed the maximum but don't limit him in typing.
Whatever Javascript you use, you will still have to validate at the server end. Users with Javascript disabled will otherwise be able to circumvent your limit.
As Javache said, you'll still have to check server side. We've been using the jQuery validator plugin which has support for Max lengths amongst tones of other stuff...
I use this, where the limit is a must. It also provides the user with the number of characters left.
function CountLength(vControl)
{
var strValue = vControl.value;
var vMax = 480;
var vLeft = vMax - strValue.length;
if (vLeft < 0)
{
vLeft = 0;
}
var vMessage = returnObjById('TextCounter');
if (document.all)
{
vMessage.innerText = vLeft + ' characters remaining.';
}
else
{
vMessage.textContent = vLeft + ' characters remaining.';
}
if (vLeft == 0)
{
vControl.value = vControl.value.substring(0, vMax);
}
}
jQuery also provides some options here. Options, options, and options.

Resources