I have what should be a simple thing but my unfamiliarity with .NET and web programs is hindering me. I'm a straight up old-school C programmer who has been programming ASP and ASP.NET lately for an ecommerce site.
I have an ASP program that synchronizes 2 databases. I also have a VB.NET program compiled down to an EXE that fills the source database before the synch happens. In the back of my mind I know I should be able to link the VB & ASP .NET programs together since that's the power of .NET. Alternatively, if I could run the EXE from ASP it would be just as well for my project. I do have the source to both programs. The ASP script was written with a text editor - the VB was in VB 2008 Express.
Please assume I know nothing of linking assemblies and such because I don't - I just read that in an article. I'd prefer ASP but if necessary I could use the ASP.NET script to launch the EXE. The code is legacy ASP with VBScript so all our ASP.NET stuff is the VB flavor as well. C# makes my other programmer's head hurt so for his sake this will have to remain VB.
Is there a way I can relatively easily launch the EXE pre-sync program and have it run when the ASP synch script starts?
The server is MS Windows Server 2003 SP2 / IIS 6.0 / the .NET version is 2.0.50727.3603. Thanks!
By the way - I'd love to "learn to use .NET properly" but time is short for this project and in-depth research will have to wait.
EDIT: Aaron's answer below gets me most of the way to the solution but I'm getting:
Exception Details: System.ComponentModel.Win32 Exception: Access is denied
Source Error: Line 17: process1.Start();
Ideas anyone?
SOLUTION: Aaron's answer below plus the knowledge that ~/ in MapPath is the virtual root of the website and the file to run is relative to that.
// Create An instance of the Process class responsible for starting the newly process.
System.Diagnostics.Process process1 = new System.Diagnostics.Process();
// Set the directory where the file resides
process1.StartInfo.WorkingDirectory = Request.MapPath("~/");
// Set the filename name of the file you want to open
process1.StartInfo.FileName = Request.MapPath("foo.exe");
// Start the process
process1.Start();
If you have the source for both then you could open the project for the EXE and copy the functionality to a new class library, then reference this class library in the web app and call the method that does the database filling from the web app.
Related
I have inherited responsibility of setting up IIS after a server migration. I have never used IIS before, however, I am the only one in my shop that has the programming ability to modify our intranet site(which is rare and wrote 10+ years ago by someone no longer here), which is hosted on the IIS. I have limited exposure to .NET.
We were at IIS 6.0 and migrated to IIS 8.5.
The intranet site is written in VBScript. There is a .asp script that uses a DLL. The DLL is 32 bit.
Here is a sample of the script and call:
<%response.write(DataTypeConversion.ConvertDate(x.value,"1","0"))%>
The DLL is named DataTypeConversion.dll Within the DLL is a function ConvertDate().
Currently, when this piece of code executes, the script errors out and stops running. I have tried to register the DLL with REGSVR32.
I have read where this may be an issue of IIS now being 64 bit trying to use a 32 bit DLL. However, I have had no luck on that front either.
So, if I were to write a custom DLL, how can I make that DLL callable in a script like in the code example above?
Thanks
In .NET, you could make a "Class Library" project. Then, under "Project", "Properties", Application, "Assembly Information...", check the box to "Make assembly COM-Visible". You might also want to read about "Strong Names".
This SO article has some pretty thorough instructions: How to access .Net dll in classic asp?
I need to write a program which will send out e-mails...
It needs to be set up as a scheduled task in Windows and be called on demand from an ASP.NET website.
I know how to write an executable (and my ASP.NET website is near completion).
I know how to code the program, but I wish to avoid duplicating my code in two places!
My first idea was to code a .exe, set it up as a scheduled task, and call it from the code in the ASP.NET website e.g. button_clicked but I'm not so sure this is a good idea.
Is there a better way (more secure, but without much more effort)?
It's an ASP.NET Website Project (not an application) it's not part of a solution - should it have been?.
If you have access to the GAC on the server, then just abstract the code out of the EXE and into a library assembly. Add the library DLL to the GAC. Then reference that DLL from both the EXE and the Web project.
If you don't have access to the GAC you can still do it, just deploy the DLL with the EXE and in your web app's bin.
EDIT
here's how to create a library assembly http://broadcast.oreilly.com/2010/07/understanding-c-namespaces-and.html
Have the sending code inside of ASP.NET and have the scheduled task request a password-protected URL on your website (e.g. /send-mails?pw=jdgdifgnfdhg). That way you don't need an EXE. You can execute the http request using curl.exe. Super simple.
I am trying to use activeX to start a windows form application written in C# from my ASP.net website. When I click a button I would like a new page to open up and activeX on that page would call my windows application.
I am using Visual Studio 2010. I have followed this tutorial: http://dotnetslackers.com/articles/csharp/WritingAnActiveXControlInCSharp.aspx
However, that tutorial is only for 1 C# file which you compile via console.
My questions are the following:
1.How would I compile the entire windows form project to use the /t:library and regasm?
2.I have followed this question answer to modify my windows form application: How do I create an ActiveX control (COM) in C#?. However, like in both examples, they do not have a Main method. When I tried to modify the code of my windows form app, I get the error saying the program does not have a Main method for entry if I take it out and replace it with a Launch() method. I am sure I am missing something?
3.Would I just write the java script on the new .aspx page to access the application?
P.S. I am trying to open this open source windows form application: http://www.codeproject.com/Articles/239849/Multiple-face-detection-and-recognition-in-real-ti
Thank you kindly
You can not do that. It would be huge security risk to allow websites to execute arbitrary code on local machine, outside of some sandboxed environment (like JavaScript for example).
AFAIK closest thing to what you want is ClickOnce, that is a installer and use it to install your WinForms app on client machine. It's easy to make installation for project, just right click in VS and publish.
There is a solution that you may be able to use called ClickOnce.
http://msdn.microsoft.com/en-us/library/t71a733d%28v=vs.100%29.aspx
I've created enterprise applications that I deploy to an internet accessible location and link my users to the "publish" website that allows them to click, install, and run the application.
Keep in mind that this will install the application in addition to running it, so if part of your requirements is to not install it, then ClickOnce won't work for your scenario.
I would suggest you can create ActiveX control instead of a Windows Form. You can create it using legacy VB (VB 6.0). You can refer something like
http://www.visualbasicbooks.com/activeXtutorial.html
http://blogs.msdn.com/b/ajma/archive/2004/08/12/213868.aspx
I have C++ project that compiles as DLL Assembly in .NET 3.5 SP1
Project is used for Image rendering processing by using WPF (it loads 2 images from local folder, applies one image on another and saves the output file in the same folder).
I want to use that that project as a reference in ASP.NET project to the rendering on the website.
So I created simple Web Project in ASP.NET C# that uses C++ project as a Reference.
Everything works great in ASP.NET Web Development Server (built-in Web server in VS2008).
But once I publish this project to IIS on the same Machine or use IIS for debug instead of built-in Web server Image rendering it's not working anymore. I'm not getting any exceptions or error messages, it just output image is not processes as it supposed to be.
If anyone know what could cause that I would really appreciate your insight!
Do you have access to the Event Logs? You should check there for any errors. You should try to throw an exception from a C#-only code path and make sure that everything is OK and regular exceptions are being thrown. Is the C++ compiled to managed code, or is native code? You might find that ASP.NET does not have the appropriate code access security permissions and needs to be registered in the GAC of the server to accessed from C#.
You should also check whether the DLL is thread-safe. This has caused issues for other users in ASP.NET/IIS.
Its been a long time since I had to do anything but minor fixes with ASP.NET and I've never deployed a ASP.NET 2.0/3.5 application so probably I'm just missing something simple but I definitely need help.
Basically, we have a poorly written .NET 1.1 web application and we had some contractors come in and break some of our third-party dependencies and update it to a poorly written .NET 3.5 web application (the poorly written part will be addressed later).
So now I'm practicing deployment scenarios on a virtual machine set up like our deployment environment.
I installed the 3.5 framework
I compiled the new code and used visual studio's Build>Publish option as recommended by the contractors to output only the files the application requires.
I copied all the files to a new directory inside of Inetpub on the VM and configured the web.config
I created a new application pool
I created a new IIS website pointed to the new directory and using the new application pool. I configured it to use version 2.0 under the IIS ASP.NET tab
But navigating to the loginpage I get:
Parser Error Message: The file '/View/LoginPage.aspx.cs' does not exist.
Line 1: <%# Page Language="C#" MasterPageFile="~/MasterPage/LoginMasperPage.Master" AutoEventWireup="true"
Line 2: CodeFile="LoginPage.aspx.cs" Inherits="MyApp.View.LoginPage" Title="MyApp - Login Page" %>
What gives? In the .NET 1.1 version of the application all the c# code was compiled into the MyApp.dll and the application knew to look there. Double checking with reflector, all the code is in the binary here too, just the server isn't looking there for it.
What can be going on? I can wait for the contractors to get in tomorrow, or compile everything including the aspx files into the binary, but we have good reasons for keeping the aspx files uncompiled and I'd like to deploy today if possible.
Please note, that this is not ASP.NET MVC, the view namespace/directory is simply where all the webforms are kept
You have probably used the Web site model for your updated application. Consider using a Web application project instead.
Change the CodeFile= reference to CodeBehind= in the "<%# Page" directive.
In visual studio try this. Click on your web application project. Go to Build > PUblish > Choose the location > click publish. That will build everything and put all the .cs files into a single dll file. It will also leave your html/aspx files in their same locations. This allows you to do what you need to do with the aspx code, while keeping all your cs hidden away.