Run ASP.NET project inside a Windows Forms Application? - c#

We have a very simple asp.net project that's composed of the following: Home.aspx, web.config, and a few images that Home.aspx uses. This webform also connects to a sql server database.
So let's say a client purchases our website app. So we go to their offices and we first install the SQL Server database in a server within their network.
Now, this is where I'm stuck: once we create the database (and configure web.config), we want to hand our client a Windows Application (ie. an EXE) that, when double-clicked, will open a Windows Form with a browser control that will display [Home.aspx].
The issue is that I want to include everything in this Windows executable. All images, [Home.aspx], web.config will be included in this executable. The only reason [Home.aspx] would go beyond this Windows Executable is to connect to the sql server database that's in the network. It's as if the Windows Application has everything needed to host this website.
Is this possible?
Thanks.

Dude the Only way of doing this is either making your ASP.NET Web application a web API on a host server or making it an API on Local Host. So if you are trying to do it on client's Machine you will be needing IIS Installed over that machine. Here is a Complete Guide that how you can Run ASP.NET Web API in your Windows form application. So what you have to do is
1: Make your ASP.NET Web API
2: Make your Windows Form Application
3: Call that API from your Windows Form Application
4: Enjoy
Cheers

It is very likely that you need to ship a web server with your WinForms app, such as
http://ultidev.com/products/UWS-Cassini-Pro/Default.aspx
https://cassinidev.codeplex.com/

C# program that shows WebBrowser event handlers
You can also set the Url property to change the current page. As with other controls, the WebBrowser offers event handlers. These trigger when a page is being loaded and when the page is loaded. Here
using System;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// When the form loads, open this web page.
webBrowser1.Navigate(" http://localhost/Home.aspx");
}
private void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e)
{
// Set text while the page has not yet loaded.
this.Text = "Navigating";
}
private void webBrowser1_DocumentCompleted(object sender,
WebBrowserDocumentCompletedEventArgs e)
{
// Better use the e parameter to get the url.
// ... This makes the method more generic and reusable.
this.Text = e.Url.ToString() + " loaded";
}
}
}

Related

Launching Slack via C# code causes error during login with token on Web

I am trying to launch it via simple code when hyperlink is clicked and using its deeplink: slack:\\open
private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e)
{
Hyperlink hyperlink = (Hyperlink)sender;
Process.Start(new ProcessStartInfo(hyperlink.NavigateUri.AbsoluteUri));
}
Error I am getting on Slack is below:
This can be reproduced if you ran Powershell as admin and launch the app and try to login to web it won't connect to desktop app.
I sure know there's a workaround if you click on "Copy Sign-In Key" but I want to avoid that error message.
Potential cause is that C# process launches Slack via System instead of using current User.
I am trying to explore using impersonation but could not seem to find the right code to be used.

Is it possible for me to open a native application (Example Microsoft Whiteboard) of windows in my c# windows form application?

Below is an example of how I open Zoom and Teams
private void button2_Click_1(object sender, EventArgs e)
{
string user = System.Windows.Forms.SystemInformation.UserName.ToString();
System.Diagnostics.Process.Start("C:/Users/" + user + "/AppData/Local/Microsoft/Teams/current/Teams.exe");
}
private void button1_Click_1(object sender, EventArgs e)
{
string user = System.Windows.Forms.SystemInformation.UserName.ToString();
System.Diagnostics.Process.Start("C:/Users/" + user + "/AppData/Roaming/Zoom/bin/Zoom.exe");
}
Note: Unlike Zoom and Teams that when installed they create a folder where we find all the installation supplements, but Whiteboard does not have any folder against these supplements. That's why it's very difficult to open it from my application in C#
Microsoft Whiteboard is a store app.
Here's a Post about How to open Microsoft Store apps from Command Prompt?
You can find these apps here:
shell:AppsFolder
From CMD you can start it with
explorer.exe shell:appsFolder\Microsoft.Whiteboard_8wekyb3d8bbwe!Whiteboard
From code it can be started this way:
System.Diagnostics.Process.Start(#"C:\Windows\explorer.exe shell:appsFolder\Microsoft.Whiteboard_8wekyb3d8bbwe!Whiteboard");
Another example can be found here:
https://notepad.onghu.com/2020/launch-win10-app-from-cmdline/
From the code it seems like you just want to start the process, not run it directly on your winform app. By default, applications downloaded from Microsoft Store are stored in C:/Program Files/WindowsApps.

How can I control the a application from a other form windows application in C#?

I want to make a form Windows application in C# with just a button . when the user click on button the one of Browser google chrome or muzila or explorer become open and show the option or setting page of Browser .
Now I can open the browser with this cods . I need control the Browser for show options or refresh or Stop .
private void button1_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("chrome.exe") ;
}
If you want to start a specific website the code is:
System.Diagnostics.Process.Start("http://www.webpage.com");
If you want to start a specific browser at a specific website the code is:
System.Diagnostics.Process.Start("iexplore.exe", "http://www.webpage.com");

Visual Studio 2010 Web application did not reflect User Name and User Domain at client machine

I have created a web application using Visual Studio 2010 on a Windows Server 2008 with the code as follows:
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = Environment.UserDomainName.ToString() + " " + Environment.UserName.ToString();
}
I notice that when I debug / run the web application at the server, the user and the user domain is correctly display on the web application via the Label1 label box.
However, when I publish the web application to IIS and access it from a client machine. The user and the user domain is not display at all.
The client machine is connected to another domain and so I was wondering if this affect the code above from displaying the user name and the user domain at the client machine?
Appreciate any help offered.
you can use
HttpContext.Current.User.Identity.Name;
Link : http://msdn.microsoft.com/fr-fr/library/system.web.httpcontext.user.aspx
Check this post below:
Getting a users DOMAIN/username from a web application
How can I get the domain name and username?
Best Regards

Open Internet Explorer from Google Chrome

I currently developing a ASP.NET web application.
The application is designed for Google Chrome. I would like to pop out IE when printing is involved because Chrome lack preview etc. at a button click the IE should open. Here's the code:
protected void btn_print_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("http://localhost/storeapp/printpage.aspx?orderno=" + Request.QueryString["orderno"].ToString() + "");
}
Here I have passed a particular orderno to the URL. But when I click nothing happens. I have set IE as default web browser. Why is this?
There is no error shown? Any ideas?
What you are trying to do will only open an IE window on the SERVER not on the client machine. You cannot (for obvious security reasons) start a process on the clients machine.
You cannot force a client browser to open a link in a different browser.
You cannot force server to open process on Client side, what you have now is opening it on the Server side which is not desired behavior I believe.

Categories

Resources