Showing posts with label matrix. Show all posts
Showing posts with label matrix. Show all posts

Saturday, March 31, 2012

Sendkeys not declared?


I just downloaded ASP.Net Web Matrix and I'm really enjoying using it, even though I only know what I am doing about 10% of the time. The one problem I've encountered is that I can't get a VB "SendKeys" statement to work in an ASPX page. I have a really simple script written. Here it is:
Sub Button1_Click(sender As Object, e As EventArgs)
Shell ("notepad", 1)
SendKeys ("%", True)
End Sub
The button code is:
<form id="form1" runat="server">
<asp:Button id="Button1" onclick="Button1_Click" runat="server" Text="Button"></asp:Button>
</form>
When I run the page, it returns an error that states: "SendKeys statement not declared." Originally, I had no parentheses around "%, True," but ASP.NET demanded it so I put it in. Any help would be greatly appreciated. I am SendKeys-dependent.

Hi,

In .NET SendKey is a class declared in System.Windows.Forms namespace. You can use it as follows:

SendKeys.SendWait("%")

But... It is really not a good idea to open notepad at server from ASP.NET application. Is this what you intend to do?


Thank you so very much for your response. I am continuing to get the same error message, even after adaptation of the command to Sendkeys.Sendwait:

"Compiler Error Message:
BC30451: Name 'SendKeys' is not declared."

I had previously located Sendkeys as an identified namespace within System.Windows.Forms, but I am not sure what to do with that information beyond that. Is there something I need to do to get the page to "talk" with that class or namespace?

As for your caution, I appreciate it. Have read the warnings. The application is going to run only on my PC. Does that minimize the concern?
Again, thank you for your time.


Hi,
You have to reference System.Windows.Forms.dll to use this method.
I think what you want to do is to open notepad from client script and not from server side code. You can use scripting host to do it. In vbscript it will look like this:
Dim WshSHell
set WshShell = CreateObject("WScript.Shell")
WshShell.Run("notepad")
WScript.Sleep(100)
WshShell.AppActivate("Notepad")
WScript.Sleep(100)
WshShell.SendKeys("abc")

Thursday, March 22, 2012

Serious Probelm

Hi all,

I am using Web Matrix and C#. When I run code in .aspx file at home on my laptop, it works perfect with no errors. However when I try and run it on a computer in my college lab I get the following errors....

Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.

Exception Details: System.Security.SecurityException: Request failed.

Source Error:

The source code that generated this unhandled exception can only be shown when compiled in debug mode. To enable this, please follow one of the below steps, then request the URL:

1. Add a "Debug=true" directive at the top of the file that generated the error. Example:

<%@dotnet.itags.org. Page Language="C#" Debug="true" %
or:

2) Add the following section to the configuration file of your application:

<configuration>
<system.web>
<compilation debug="true"/>
</system.web>
</configuration
Note that this second technique will cause all files within a given application to be compiled in debug mode. The first technique will cause only that particular file to be compiled in debug mode.

Important: Running applications in debug mode does incur a memory/performance overhead. You should make sure that an application has debugging disabled before deploying into production scenario.

Stack Trace:

[SecurityException: Request failed.]
DatabaseConnect.DBConnect.Details() +0
DatabaseConnect.DBConnect.Main() +10
_ASP.common_ascx.Page_Load(Object sender, EventArgs e) +44
System.Web.UI.Control.OnLoad(EventArgs e) +55
System.Web.UI.Control.LoadRecursive() +21
System.Web.UI.Control.LoadRecursive() +84
System.Web.UI.Page.ProcessRequestMain() +2095
System.Web.UI.Page.ProcessRequest() +115
System.Web.UI.Page.ProcessRequest(HttpContext context) +18
System.Web.CallHandlerExecutionStep.Execute() +179
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +87

From my understanding of the error, it seems a security/permissions problem but not sure what I should ask or say to the administrator about it or what fix I should suggest. Any suggestions please? Also as the files will be hosted on a web server soon, is it possible I may get the same problems there?

Help is really needed on this and would be extremely appreciated.Set debug to true in the page directive. It will tell you more information then now. After that you may have more information, which will help you.
Thanks for your response sonukapoor. I have debug set to true on the .aspx page and both the user controls for this page and the same error as above is displayed.

Anymore ideas please?
As I can see in the stack you're using a database conneciton somewhere. Check what you're doing on line 44 of the common.ascx (see stack trace to find out which file it really is). An interesting post on-line is this: <a hef="http://www.error-bank.com/microsoft.public.dotnet.security/3764_Thread.aspx">http://www.error-bank.com/microsoft.public.dotnet.security/3764_Thread.aspx</a> which covers a similar situation where an Access db was used, causing security problems.
Yes this is correct I am using a Access database connection. There is no line 44 in common.ascx. The entire code for this .ascx file is

<%@. Control Language="C#" %>
<%@. import Namespace="DatabaseConnect" %>
<script runat="server"
void Page_Load(Object sender, EventArgs e) {

if(Session.IsNewSession)
{
DBConnect db = new DBConnect();
db.Main();

}

}

</script
This user control checks to see if it is a new session and if its a class is instansiated, a connection with an access database is made and data is read into variables. From what you are saying I would think the problem is with instansiating the class. Possibly I may not have sufficent permissions to instansiate a class, would this be possible?

Also I went through the link you gave and the instructions specified are not possible for me to do as I dont have admin permissions on the machine in question.
I think you need to print out that artical and give it to the admins at your school - they can make the changes. I'm sure you're not the first with this problem...
Thanks for all the help, I just emailed the administrator with the links and details.

Will report back soon.

If anyone else has any suggestions, please post as it is really important I get this sorted soon.