I need to separate IE and FF browsers from others
it's a pseudo-code :
If (CurrentBrowser == IE(6+) or FF(2+) )
{
...
}
else
{
...
}
in protected void Page_Load() event (think so)
if ((Request.Browser.Type == "IE") || (Request.Browser.Type == "FF"))
{
WebMsgBox.Show("1111");
}
no effects :-/ what is IE and FF types?
if (Request.Browser.Type.Contains("Firefox")) // replace with your check
{
...
}
else if (Request.Browser.Type.ToUpper().Contains("IE")) // replace with your check
{
if (Request.Browser.MajorVersion < 7)
{
DoSomething();
}
...
}
else { }
Here's a way you can request info about the browser being used, you can use this to do your if statement
System.Web.HttpBrowserCapabilities browser = Request.Browser;
string s = "Browser Capabilities\n"
+ "Type = " + browser.Type + "\n"
+ "Name = " + browser.Browser + "\n"
+ "Version = " + browser.Version + "\n"
+ "Major Version = " + browser.MajorVersion + "\n"
+ "Minor Version = " + browser.MinorVersion + "\n"
+ "Platform = " + browser.Platform + "\n"
+ "Is Beta = " + browser.Beta + "\n"
+ "Is Crawler = " + browser.Crawler + "\n"
+ "Is AOL = " + browser.AOL + "\n"
+ "Is Win16 = " + browser.Win16 + "\n"
+ "Is Win32 = " + browser.Win32 + "\n"
+ "Supports Frames = " + browser.Frames + "\n"
+ "Supports Tables = " + browser.Tables + "\n"
+ "Supports Cookies = " + browser.Cookies + "\n"
+ "Supports VBScript = " + browser.VBScript + "\n"
+ "Supports JavaScript = " +
browser.EcmaScriptVersion.ToString() + "\n"
+ "Supports Java Applets = " + browser.JavaApplets + "\n"
+ "Supports ActiveX Controls = " + browser.ActiveXControls
+ "\n";
MSDN Article
Try the below code
HttpRequest req = System.Web.HttpContext.Current.Request
string browserName = req.Browser.Browser;
private void BindDataBInfo()
{
System.Web.HttpBrowserCapabilities browser = Request.Browser;
Literal1.Text = "<table border=\"1\" cellspacing=\"3\" cellpadding=\"2\">";
foreach (string key in browser.Capabilities.Keys)
{
Literal1.Text += "<tr><td>" + key + "</td><td>" + browser[key] + "</tr>";
}
Literal1.Text += "</table>";
browser = null;
}
I would not advise hacking browser-specific things manually with JS. Either use a javascript library like "prototype" or "jquery", which will handle all the specific issues transparently.
Or use these libs to determine the browser type if you really must.
Also see Browser & version in prototype library?
For browser compatibility you can use this code. This method returns browser name and version :
private string GetBrowserNameWithVersion
{
var userAgent = Request.UserAgent;
var browserWithVersion = "";
if (userAgent.IndexOf("Edge") > -1)
{
//Edge
browserWithVersion = "Edge Browser Version : " + userAgent.Split(new string[] { "Edge/" }, StringSplitOptions.None)[1].Split('.')[0];
}
else if (userAgent.IndexOf("Chrome") > -1)
{
//Chrome
browserWithVersion = "Chrome Browser Version : " + userAgent.Split(new string[] { "Chrome/" }, StringSplitOptions.None)[1].Split('.')[0];
}
else if (userAgent.IndexOf("Safari") > -1)
{
//Safari
browserWithVersion = "Safari Browser Version : " + userAgent.Split(new string[] { "Safari/" }, StringSplitOptions.None)[1].Split('.')[0];
}
else if (userAgent.IndexOf("Firefox") > -1)
{
//Firefox
browserWithVersion = "Firefox Browser Version : " + userAgent.Split(new string[] { "Firefox/" }, StringSplitOptions.None)[1].Split('.')[0];
}
else if (userAgent.IndexOf("rv") > -1)
{
//IE11
browserWithVersion = "Internet Explorer Browser Version : " + userAgent.Split(new string[] { "rv:" }, StringSplitOptions.None)[1].Split('.')[0];
}
else if (userAgent.IndexOf("MSIE") > -1)
{
//IE6-10
browserWithVersion = "Internet Explorer Browser Version : " + userAgent.Split(new string[] { "MSIE" }, StringSplitOptions.None)[1].Split('.')[0];
}
else if (userAgent.IndexOf("Other") > -1)
{
//Other
browserWithVersion = "Other Browser Version : " + userAgent.Split(new string[] { "Other" }, StringSplitOptions.None)[1].Split('.')[0];
}
return browserWithVersion;
}
I tried and found the solution for the same
public static string GetBrowserDetails()
{
string BrowserDetails = HttpContext.Current.Request.Browser.Browser + " - " + HttpContext.Current.Request.Browser.Version + "; Operating System : " + HttpContext.Current.Request.Browser.Platform;
return BrowserDetails;
}
OUTPUT :
Chrome - 88.0; Operating System : WinNT
use from
Request.Browser
this link will help you :
Detect the browser using ASP.NET and C#
Related
Is there a way to add a pause (preferably 1 second) in Amazon Alexa without using SSML? Perhaps there is a trick I can do with the Outputspeech.Text and I just don't know it.
Below, I am saying "Here are works of art by {artist name}" but the name and the start of the works of art become mixed together - in spite of the period - so I end up with things like "Here are the works of art by Pablo Picasso Harlequin..."
I am using C# and my own https endpoint, not AWS Lambda.
Any suggestions? Otherwise I will add it as SSML. Thanks.
var output = new StringBuilder();
var outputCard = new StringBuilder();
string m_location;
string m_current_location;
string m_artist = dt_artist.Rows[0]["DisplayName"].ToString();
output.Append("here are works of art for " + m_artist + ". ");
outputCard.Append("Here are works of art for " + m_artist + ".\n\n");
foreach (DataRow dr in dt_artist_objs.Rows)
{
m_current_location = dr["CurrentLocation"].ToString();
if (m_current_location == " ")
{
m_location = "The location is not available.";
}
else
{
m_location = "It is located on the " + m_current_location;
}
output.Append(dr["Title"].ToString() + " is a " + dr["Classification"].ToString() + ". The medium is " + dr["Medium"].ToString() + ". " + m_location);
outputCard.Append(dr["Title"].ToString() + ", " + dr["Dated"].ToString() + " is a " + dr["Classification"].ToString() + ". The medium is " + dr["Medium"].ToString() + ". " + dr["Creditline"].ToString() + ". " + m_location + ".\n"); // It is located on the " + dr["CurrentLocation"].ToString());
}
sql_conn_data.Close();
response.Response.OutputSpeech.Text = output.ToString();
response.Response.Card.Title = "Art";
response.Response.Card.Type = "Standard";
response.Response.Card.Text = outputCard.ToString();
response.Response.ShouldEndSession = true;
return response;
UPDATE
OK. Ended up going the SSML route which looks like this:
var output = new StringBuilder();
var outputCard = new StringBuilder();
string m_location;
string m_current_location;
string m_location_card;
string m_artist = dt_artist.Rows[0]["DisplayName"].ToString();
output.Append("<speak>");
output.Append("here are works of art for " + m_artist + ". <break time='1s'/> ");
outputCard.Append("Here are works of art for " + m_artist + ".\n\n");
foreach (DataRow dr in dt_artist_objs.Rows)
{
m_current_location = dr["CurrentLocation"].ToString();
if (m_current_location == " ")
{
m_location = "The location is not available. <break time='1s' />";
m_location_card = "The location is not available. ";
}
else
{
m_location = "It is located on the " + m_current_location + "<break time = '1s' />";
m_location_card = "It is located on the " + m_current_location;
}
output.Append(dr["Title"].ToString() + " is a " + dr["Classification"].ToString() + ". The medium is " + dr["Medium"].ToString() + ". " + m_location);
outputCard.Append(dr["Title"].ToString() + ", " + dr["Dated"].ToString() + " is a " + dr["Classification"].ToString() + ". The medium is " + dr["Medium"].ToString() + ". " + dr["Creditline"].ToString() + ". " + m_location_card + ". \n");
}
output.Append("</speak>");
sql_conn_data.Close();
response.Response.OutputSpeech.Ssml = output.ToString();
response.Response.OutputSpeech.Type = "SSML";
response.Response.Card.Title = "Art";
response.Response.Card.Type = "Standard";
response.Response.Card.Text = outputCard.ToString();
response.Response.ShouldEndSession = true;
return response;
}
There is not a way to introduce a pause in Alexa without SSML. You will need to build the ssml string and return it back to Alexa using the pause, or the cadence strings.
I have to do if user's browser compatibility is on then need to show message to user that your browser's compatibility is on.
I have searched this a lot on google but yet not found a proper answer.
I have tried below code but HttpContext.Current.Request.UserAgent always contains MSIE 7.0
string isOn = string.Empty;
if (HttpContext.Current.Request.UserAgent.IndexOf("MSIE 7.0") > -1)
{
isOn = "IE8 Compatibility View";`
}
else
{
isOn = "IE8";
}
}
You may try like this
if (Request.Browser.Type.ToUpper().Contains("IE"))
{
if (Request.Browser.MajorVersion < 7)
{
//Show the message here
}
...
}
else if (Request.Browser.Type.Contains("Firefox"))
{
//code to show message
}
else if (Request.Browser.Type.Contains("Chrome"))
{
//code to show message
}
Also check this MSDN which has its own way of detecting the browser
Query the Browser property, which contains an HttpBrowserCapabilities
object. This object gets information from the browser or client device
during an HTTP request, telling your application the type and level of
support the browser or client device offers. The object in turn
exposes information about browser capabilities using strongly typed
properties and a generic name-value dictionary.
private void Button1_Click(object sender, System.EventArgs e)
{
System.Web.HttpBrowserCapabilities browser = Request.Browser;
string s = "Browser Capabilities\n"
+ "Type = " + browser.Type + "\n"
+ "Name = " + browser.Browser + "\n"
+ "Version = " + browser.Version + "\n"
+ "Major Version = " + browser.MajorVersion + "\n"
+ "Minor Version = " + browser.MinorVersion + "\n"
+ "Platform = " + browser.Platform + "\n"
+ "Is Beta = " + browser.Beta + "\n"
+ "Is Crawler = " + browser.Crawler + "\n"
+ "Is AOL = " + browser.AOL + "\n"
+ "Is Win16 = " + browser.Win16 + "\n"
+ "Is Win32 = " + browser.Win32 + "\n"
+ "Supports Frames = " + browser.Frames + "\n"
+ "Supports Tables = " + browser.Tables + "\n"
+ "Supports Cookies = " + browser.Cookies + "\n"
+ "Supports VBScript = " + browser.VBScript + "\n"
+ "Supports JavaScript = " +
browser.EcmaScriptVersion.ToString() + "\n"
+ "Supports Java Applets = " + browser.JavaApplets + "\n"
+ "Supports ActiveX Controls = " + browser.ActiveXControls
+ "\n"
+ "Supports JavaScript Version = " +
browser["JavaScriptVersion"] + "\n";
TextBox1.Text = s;
}
I have the following call to javascript:
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
this._BtAdd.Attributes.Add("onclick", "GXDualListBox_MoveDualList(" + sourceListId + ", " + destListId + ", " + selectedValuesId + ", false, true, "+ this._SortByDescription +");");
this._BtRemove.Attributes.Add("onclick", "GXDualListBox_MoveDualList(" + destListId + ", " + sourceListId + ", " + selectedValuesId + ", false, false, " + this._SortByDescription + ");");
if (!this._PostBackOnAll)
{
this._BtAddAll.Attributes.Add("onclick", "GXDualListBox_MoveDualList(" + sourceListId + ", " + destListId + ", " + selectedValuesId + ", true, true, " + this._SortByDescription + " );");
this._BtRemoveAll.Attributes.Add("onclick", "GXDualListBox_MoveDualList(" + destListId + ", " + sourceListId + ", " + selectedValuesId + ", true, false, " + this._SortByDescription + " );");
}
// Check if user can double-click on listbox item to move it
if (this._AllowDblClick)
{
this._LstSource.Attributes.Add("ondblclick", "GXDualListBox_MoveDualList(" + sourceListId + ", " + destListId + ", " + selectedValuesId + ", false, true, " + this._SortByDescription + " );");
this._LstDestination.Attributes.Add("ondblclick", "GXDualListBox_MoveDualList(" + destListId + ", " + sourceListId + ", " + selectedValuesId + ", false, false, " + this._SortByDescription + " );");
}
}
this._SortByDescription is bool which would be false in this case. The javascript is as follows:
function GXDualListBox_MoveDualList(srcList, destList, selectedValues, moveAll, isAdd,sortByDescription)
{
if ((srcList.selectedIndex == -1) && (moveAll == false)) {
return;
}
newDestList = new Array(destList.options.length);
for (var len = 0; len < destList.options.length; len++) {
if (destList.options[len] != null) {
newDestList[len] = new Option(destList.options[len].text, destList.options[len].value, destList.options[len].defaultSelected, destList.options[len].selected);
}
}
for (var i = 0; i < srcList.options.length; i++) {
if (srcList.options[i] != null && (srcList.options[i].selected == true || moveAll)) {
newDestList[len] = new Option(srcList.options[i].text, srcList.options[i].value, srcList.options[i].defaultSelected, srcList.options[i].selected);
len++;
}
}
if (sortByDescription) {
newDestList.sort(GXDualListManager_CompareOptionValues);
newDestList.sort(GXDualListManager_CompareOptionText);
}
for (var j = 0; j < newDestList.length; j++) {
if (newDestList[j] != null) {
destList.options[j] = newDestList[j];
}
}
}
if (isAdd)
buildSelectedList(destList, selectedValues);
else
buildSelectedList(srcList, selectedValues);
}
When I hard code this._SortByDescription as 'false' in the javascript call, it works. But replacing 'false' with this._SortByDescription results in error. Also I observed while debugging that the javascript receives the value of this._SortByDescription as 'False' instead of 'false'. Not sure if this matters.
I am working on javascript for the first time. Please help.
Try converting to lower case:
this._SortByDescription.ToLower();
If the property of type bool:
this._SortByDescription.ToString().ToLower();
You could also define "True" and "False" in the beginning of your function/JS. It may seem tedious, but it worked for me.
function xxx {
var True = true;
var False = false;
// code...
}
As discussed, it is False in the land of c#, but false in javascript. You just have to rejig your code so that it is returning the LC version.
this._SortByDescription ? "true" : "false"
I faced something similar. I had scriptlets in my ASP pages and this failed for the same reason:
isSubSpeciesAspect = <%=Model.aspect.ToLower() === "subspecies"%>;
In the generated JS this came out as:
isSubSpeciesAspect = True;
I just had to move things around to fix this problem:
isSubSpeciesAspect = ("<%=Model.aspect.ToLower()%>" === "subspecies");
Is there a way to get the message box to close and return to the form without it emailing the data?
halfway there atm just need a help with the second if/else if statement. I'm very new to all this.
my code is below :)
//Button
private void submitButton_Click(object sender, EventArgs e)
{
string software = null;
string hardware = null;
foreach (string s in softwareNeededCheckedListBox.CheckedItems)
{
software = software + '\n' + s;
}
foreach (string s in hardwareNeededCheckedListBox.CheckedItems)
{
hardware = hardware + '\n' + s;
}
if (yesRadioButton.Checked == true)
{
yesRadioButton.Text = "Yes";
noRadioButton.Text = " ";
}
if (noRadioButton.Checked == true)
{
noRadioButton.Text = "No";
yesRadioButton.Text = " ";
}
if (MessageBox.Show("First name: " + firstNameTextBox.Text + " " + "Last name: " + lastNameTextBox.Text + "\n" + "\n" +
"Will be working in " + areaOfTheCompanyComboBox.SelectedItem + "\n" + "\n" +
"They will need the following software:" + software + "\n" + "\n" +
"They will need the following hardware:" + hardware + "\n" + "\n" +
"They will be seated: " + seatingLocationRichTextBox.Text + "\n" + "\n" +
"Any further Comments: " + notesRichTextBox.Text + "\n" + "\n" +
"Do they require a phone: " + noRadioButton.Text + yesRadioButton.Text + "\n" + "\n" +
"Date they start: " + completionDateTimePicker.Text + "\n" + "\n" +
"Are you happy with the information shown above?" + "\n" + "\n" +
MessageBoxButtons.OKCancel) == DialogResult.OK)
{
MailMessage mail = new MailMessage();
SmtpClient smtpserver = new SmtpClient("smtp.gmail.com");
mail.From = new MailAddress("xxxxx#gmail.com");
mail.To.Add("xxxxx#xxxxxx.co.uk");
mail.Subject = "Test Mail";
mail.Body = "First name: " + firstNameTextBox.Text + " " + "Last name: " + lastNameTextBox.Text + "\n" + "\n" +
"Will be working in " + areaOfTheCompanyComboBox.SelectedItem + "\n" + "\n" +
"They will need the following software:" + software + "\n" + "\n" +
"They will need the following hardware:" + hardware + "\n" + "\n" +
"They will be seated: " + seatingLocationRichTextBox.Text + "\n" + "\n" +
"Any further Comments: " + notesRichTextBox.Text + "\n" + "\n" +
"Do they require a phone: " + noRadioButton.Text + yesRadioButton.Text + "\n" + "\n" +
"Date they start: " + completionDateTimePicker.Text;
smtpserver.Port = 587;
smtpserver.Credentials = new System.Net.NetworkCredential("**", "********");
smtpserver.Send(mail);
MessageBox.Show("Your Form has been sent ");
}
You actually forgot you place commas to your MessageBox.Show to have the correct arguments/parameters.
if (MessageBox.Show("Body of your message box",
"Title Of Your MessageBox",
MessageBoxButtons.OKCancel,
MessageBoxIcon.Information) == DialogResult.OK)
{
}
That will only e-mail if the user clicks OK. You can handle the cancel button by using DialogResult.Cancel
I would personally put the MessageBox in a dialogResult variable. For instance:
var dialogResult = MessageBox.Show("FIrst name .... ");
Then you can check if the user pressed OK or Cancel
if (dialogResult == DialogResult.OK) {
// Send the e-mail
} else if (dialogResult == DialogResult.Cancel) {
// Do what you need to do / return to the form.
}
To show a messagebox with OK and Cancel you need:
MessageBox.Show(this, "Message", "Title", MessageBoxButtons.OKCancel);
I'm using the following code:
if (e.Data.MessageArray[0] == "!streams")
{
try
{
WebClient webclient = new WebClient();
var data = webclient.DownloadString("http://api.justin.tv/api/stream/list.json?channel=dotademon");
JArray ja = JArray.Parse(data);
WebClient webclient2 = new WebClient();
var data2 = webclient2.DownloadString("http://api.justin.tv/api/stream/list.json?channel=trixilulz");
JArray ja2 = JArray.Parse(data2);
WebClient webclient3 = new WebClient();
var data3 = webclient3.DownloadString("http://api.justin.tv/api/stream/list.json?channel=thepremierleague");
JArray ja3 = JArray.Parse(data3);
string streamingString = "Live right now: ";
streamingString += (char)3 + "03EG.Demon" + (char)15 + " - " + "Viewers: " + ja[0]["channel_count"] + " - " + "http://www.justin.tv/dotademon" + (char)3 + "03 Mouz.Trixi" + (char)15 + " - " + "Viewers: " + ja2[0]["channel_count"] + " - " + "http://www.justin.tv/trixilulz" + (char)3 + "03 The Premier League" + (char)15 + " - " + "Viewers: " + ja3[0]["channel_count"] + " - " + "http://www.justin.tv/thepremierleague";
irc.SendMessage(SendType.Message, e.Data.Channel, streamingString);
Console.WriteLine("EG.Demon is " + ja[0]["format"]);
Console.WriteLine("Mouz.Trixi is " + ja[2]["format"]);
Console.WriteLine("The Premier League is " + ja[3]["format"]);
}
catch (ArgumentOutOfRangeException)
{
//catch something
}
}
However, if one of the streams aren't online, then it doesn't output that string at all. Even if 2 are online and 1 is offline and vice versa. However, if they're all online, then it outputs it correctly like:
Live right now: EG.Demon - Viewers: 164 - http://www.justin.tv/dotademon Mouz.Trixi - Viewers: 49 - http://www.justin.tv/trixilulz The Premier League - Viewers: 2992 - http://www.justin.tv/thepremierleague
To demonstrate it with outputting to console, here is that code, it essentially does the same thing as the above code, but sends it to the console, same issue though obviously:
using System;
using System.Net;
using Newtonsoft.Json.Linq;
namespace Test
{
class Program
{
static void Main(string[] args)
{
try
{
WebClient webclient = new WebClient();
var data = webclient.DownloadString("http://api.justin.tv/api/stream/list.json?channel=dotademon");
JArray ja = JArray.Parse(data);
WebClient webclient2 = new WebClient();
var data2 = webclient2.DownloadString("http://api.justin.tv/api/stream/list.json?channel=trixilulz");
JArray ja2 = JArray.Parse(data2);
WebClient webclient3 = new WebClient();
var data3 = webclient3.DownloadString("http://api.justin.tv/api/stream/list.json?channel=thepremierleague");
JArray ja3 = JArray.Parse(data3);
string streamingString = "Live right now: ";
streamingString += (char)3 + "03EG.Demon" + (char)15 + " - " + "Viewers: " + ja[0]["channel_count"] + " - " + "http://www.justin.tv/dotademon" + (char)3 + "03 Mouz.Trixi" + (char)15 + " - " + "Viewers: " + ja2[0]["channel_count"] + " - " + "http://www.justin.tv/trixilulz" + (char)3 + "03 The Premier League" + (char)15 + " - " + "Viewers: " + ja3[0]["channel_count"] + " - " + "http://www.justin.tv/thepremierleague";
Console.WriteLine(streamingString);
}
catch (ArgumentOutOfRangeException)
{
//do something
}
}
}
}
Live right now: EG.Demon - Viewers: 164 - http://www.justin.tv/dotademon Mouz.Trixi - Viewers: 49 - http://www.justin.tv/trixilulz The Premier League - Viewers: 2992 - http://www.justin.tv/thepremierleague
My question is, how can I use this as a string but output it still if it's online and not output the rest if it's offline. When at least one of them are offline, then it doesn't output it at all. It checks if it's online if it finds channel_count in the json, because if it's offline, the json file contains nothing, just []. It's the only approach I know of to check if it's online/offline. I'm using JSON.Net by the way.
You can check ja.Count to see if you got a response.
var sb = new StringBuilder("Live right now: ");
if (ja.Count > 0)
sb.Append(string.Format("EG.Demon - Viewers: {0} - http://www.justin.tv/dotademon", ja[0]["channel_count"]));
if (ja2.Count > 0)
//...
if (ja3.Count > 0)
//...
irc.SendMessage(SendType.Message, e.Data.Channel, sb.ToString());