Why doesn't my code-behind execute? - c#

I am trying to output the value of x in the following request: http://localhost:4827/Default.aspx?x=123123
I am getting no output at all.
Here is my code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;
using MPads.Common;
using MPads.WebPatientPortal.Interfaces;
using MPads.WebPatientPortal.Presenters;
using MPads.BusinessLogic.Interfaces;
using MPads.Components.Interfaces;
using MPads.DataAccess;
using MPads.DataAccess.Interfaces;
using System.Text;
using System.Diagnostics;
namespace MPads.WebPatientPortal
{
public partial class Default : System.Web.UI.Page, IDefault
{
private DefaultPresenter _presenter;
protected void Page_Load(object sender, EventArgs e)
{
Response.Cache.SetCacheability(HttpCacheability.NoCache);
_presenter = new DefaultPresenter();
var fields = Request.QueryString;
if (fields.Count > 0)
{
var x = Utilities.GetNvpValue(fields, "x").ToString();
Trace.Write(x);
}
}
public void loadAjaxContent(string content)
{
Page.RegisterStartupScript("myScript", " <script type=\"text/javascript\"> loadAjaxContent('" + content + "','POST',null); </script>");
}
public void DisplayMessage(string message)
{
}
}
}

Do you have your even handler set up in your ASPX?
Assuming that you do: Consider instead of Trace.Write(); using Response.Write();
Trace.Write(); writes to a trace listener (which you can have display at the bottom of your page).
Response.Write(); outputs text results directly to your page, not through a Trace Listener.

Use Glimpse to find out this, here's the link Glimpse-A client side Glimpse to your server

Related

Trying to transfer files for the target user

today we were trying to transfer files with using C# but there are some problems here i don't really know what is wrong
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace FileTransfer
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string curDir = Directory.GetCurrentDirectory();
var userDir = new DirectoryInfo(Environment.GetFolderPath(System.Environment.SpecialFolder.UserProfile));
string path = curDir + #"\1.jar";
string path2 = userDir + #"\Desktop\2.jar";
File.Move(path, path2);
}
}
}
It says 1.jar file cannot found.
Try this:
string path = Path.Combine(curDir,"1.jar");
string path2 = Path.Combine(userDir,"Desktop","2.jar");
//if this still doesn't work, put a breakpoint after these two lines
When your breakpoint is hit look at the value of path. Is there a even file at that location? If not, you need build your path correctly.
Also, it would be a good idea to check if the file exists before you try to move it:
if(!File.Exists(path))
{
//handle this scenario here
return;
}
File.Move(path,path2);

have exception error when using Visa.Interop.ResourceManager in C#

I'm using C# to control instrument(ex. function generator) but when using ResourceManager constructor some exception error occurs...
This is the exception System.Runtime.InteropServices.COMException'(System.Private.CoreLib.dll)
Could anyone help me with how to fix it?
I'm using Visual Studio and I've tried executing Visual Studio in administrator mode but it doesn't work either. hers's my code
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Ivi.Visa;
using Ivi.Visa.FormattedIO;
using Ivi.Visa.Interop;
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
namespace upw_test1
{
public sealed partial class MainPage : Page
{
bool isconnected;
public MainPage()
{
this.InitializeComponent();
isconnected = false;
}
void Button_Click(Object sender, RoutedEventArgs e)
{
connection_result.Text = "Hello, " + Input_num.Text + "!";
if (!isconnected)
{
string srcAddress = "GPIB::";
srcAddress += Input_num.Text.ToString();
srcAddress += "::INSTR";
try
{
ResourceManager mngr = new ResourceManager();
catch (Exception exp)
{
//MessageBox.Show(exp.Message);
connection_result.Text = srcAddress + " connection fail ";
}
// GPIB address
}
}
}
}
below is the full stack trace of exception..

tweetinvi, I can't retrieve messages

I want to monitor retrieve messages so that the bot can respond to them.
I can send pm using tweetinvi but for some reason, I can't get it to retrieve any of the messages in that account. GetLastMessage always returns a null.
I have tried the following:
in this test, I have a timer that runs every 1s and pols the messages.
private static void OnTwitterTimedEvent(Object source, System.Timers.ElapsedEventArgs e)
{
try
{
IEnumerable<IMessage> MSG = controller.GetLatestMessagesReceived(); ; // Message.GetLatestMessagesReceived(100);
if (MSG != null)
{
Console.WriteLine(MSG.ElementAt(0).SenderScreenName + MSG.ElementAt(0).Text);
if ((MSG.ElementAt(0).SenderId == ####MYID#####) & (MSG.ElementAt(0).Text == "?"))
{
Message.PublishMessage(tweet, ####MYID#####);
Console.ForegroundColor = ConsoleColor.DarkGreen;
Console.WriteLine(MSG.ElementAt(0).SenderScreenName + MSG.ElementAt(0).Text);
Console.ResetColor();
Message.DestroyMessage(MSG.ElementAt(0));
}
}
} catch
{
}
}
I have also tried
private static void OnTwitterTimedEvent(Object source, System.Timers.ElapsedEventArgs e)
{
try
{
var latestMessagesSent = Message.GetLatestMessagesSent();
var latestMessagesSentParameter = new MessagesSentParameters();
latestMessagesSentParameter.PageNumber = 239823;
var latestMessagesSentFromParameter = Message.GetLatestMessagesSent(latestMessagesSentParameter);
if (latestMessagesSentFromParameter != null)
{
Console.WriteLine("Messages Send : ");
foreach (var mms in latestMessagesSentFromParameter)
{
Console.WriteLine("- '{0}'", mms.Text);
}
}
} catch
{
}
}
I also tried using
IAuthenticatedUser authenticatedUser = User.GetAuthenticatedUser();
authenticatedUser.GetLatestMessagesReceived();
I am using
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Timers;
using System.Threading.Tasks;
using System.Collections;
using System.Globalization;
//using System.Threading;
using System.IO;
using System.Net;
using System.Diagnostics;
using System.Net;
using System.Reflection;
// REST API
using Tweetinvi;
using Tweetinvi.Models;
using Tweetinvi.Parameters;
// STREAM API
using Tweetinvi.Streaming;
using Stream = Tweetinvi.Stream;
// Others
using Tweetinvi.Exceptions; // Handle Exceptions
using Tweetinvi.Core.Extensions; // Extension methods provided by Tweetinvi
using Tweetinvi.Models.DTO; // Data Transfer Objects for Serialization
using Tweetinvi.Json; // JSON static classes to get json from Twitter.
Your app must have permission to read and write on twitter API.

Charset of executed

I have a problem with my project.
I have a js function sig7 which generates me hash.
But the charset of html page is required to be utf-8.
I try to execute this js in my C# app with library
Everything is OK, but generated hash is not valid. I think it happens because the charset of code isn't utf-8.
My app:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using Noesis.Javascript;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
StreamReader sr = new StreamReader("c://lib.js");
string script = sr.ReadToEnd();
JavascriptContext context = new JavascriptContext();
context.Run(script);
var sig = context.Run(#"sig7('057d194dd856d4f8cd15bc85fbbddbf136df809f72f5a435e6af41c1f82f950f,Id166084073,ldsclldscl');").ToString();
richTextBox1.Text = sig;
}
}
}
sig must be 1dbde1d62b6e0dca7d56f72e50c178132e236978d2dba1e2c3ada5b7b8973aeb but not 7211ed8fe85d750c26cb5abb499bfa88b7cecbe968fc6cc7efa69dc496c8ae12 which is generated by my app.
Any help?
Should this line:
var sig = context.Run(#"sig7('057d194dd856d4f8cd15bc85fbbddbf136df809f72f5a435e6af41c1f82f950f,Id166084073,ldsclldscl');").ToString();
Be:
var sig = context.Run(#"sig7('057d194dd856d4f8cd15bc85fbbddbf136df809f72f5a435e6af41c1f82f950f', 'Id166084073', 'ldsclldscl');").ToString()
?

setting up filesystem permissions

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Security.AccessControl;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
string Directoryd = "D:";
string mydirectory = Directoryd + "\\" + "rs\\";
if (!Directory.Exists(mydirectory))
{
Directory.CreateDirectory(mydirectory);
}
DirectoryInfo di = new DirectoryInfo(mydirectory);
DirectorySecurity ds = di.GetAccessControl();
ds.AddAccessRule(new FileSystemAccessRule(#"*",FileSystemRights.FullControl,AccessControlType.Allow));
di.SetAccessControl(ds);
}
}
}
this is my code when i execute this the pop up is showing that
Actually, this code is to create a folder rs and set its permission to deny full control but on running the error come with the message
Some or all identity references could not be translated.
What is the error?
You should change the following line:
ds.AddAccessRule(new FileSystemAccessRule(#"*",FileSystemRights.FullControl,AccessControlType.Allow));
to:
ds.AddAccessRule(new FileSystemAccessRule(#"Everyone",FileSystemRights.FullControl,AccessControlType.Allow));
Also if you look at the following Everyone Group there is an answer a bit further down that suggests you should use SSID's instead of the names.
Try the group "Everyone", not *.

Categories

Resources