How can I embed other applications in asp.net? - c#

I have created three projects on Visual Studio. One is the base project and I would like to embed the other two projects into the base project. I went through some articles but couldn't find something that suits my requirements (and I am still a newbie in asp.net :)). Below is a screenshot of what I created
I will like to call FirstApp and SecondApp when I run the BaseApp and also display some unique texts like "hello from FirstApp" and "hello from SecondApp".

All you need to do is create a reference to the projects you want to use, and then call the code in those projects.
You can add a reference to another project by right clicking BaseApp, select Add, and Reference. Then you get a screen where you can select the other projects in your solution. Select the ones you want to use, and you can start to use the classes in the other projects.

If you want to use FirstApp and SecondApp then create class library of those project and add those library reference in your first project [base].
After that you will get all method access in this project based on assembly type.

If what you want is to see on a page loaded from a web application another page loaded from a different web application, then you need to use iframes.
To do this you do not need even if the projects are in the same solution. They are different processes. They could even be in different domains. You are really using the http protocol to create the iframes. The applications are completely isolated.

Related

Can you call a class in a visual studio website project from a class library?

I'm creating a new VS2015 web application, but there's one piece that requires some reporting that already exists in another system.
The other system is a VS2013 solution that has a website (not web application) as it's main project, along with a number of class libraries. But the website directly contains a bunch of classes that do reporting and other things, and I would rather use those than recreate all the (very complicated) code.
Is there any way to reference the classes in the website from another project or class library? It's a rather large old application I'm maintaining, and I'd rather not try extracting all that functionality into it's own class library if I don't have to.
If those classes were already in a separate class library, I could reference them easy enough, but unfortunately they are right in the website, and I can't find any information about being able to link to it (presumably because you can't).
Here's a sample structure:
MySolution
MyNewClassLibrary
MyClass
{
MyReportFunction()
{
var x = new ReportClass(); // From website project
x.CreateReportFunction();
}
}
OldSolution
WebsiteProject
ReportClass
{
CreateReportFunction()
{
// All the code I'd like to access
]
}
Is this possible? Or do I have a lot of rewriting to do? Or would looking into converting the website into a web application be a better idea?
You can add those existing classes as linked classes into your solution.
To add an existing item to a project
In Solution Explorer, select a target project.
On the Project menu, select Add Existing Item.
In the Add Existing Item dialog box, locate and select the project item you want to add.
From the Open button drop-down list, select Add As Link.
You can also read more details here.
In case anybody else is looking for something like this, the answer is no, it's not possible.
I ended up pulling all the functionality out into a new class library project, which required massive testing to make sure I got all the little bits and pieces right.
Moral of the story - build your software properly the first time, and pull functionality out into reusable objects. Don't do procedural programming in an object-oriented language.

Two Sites from one project in Visual Studio

We're publishing two websites based out of one project.
The main site is a asp.net web forms web application, written in c#. The next one we are creating will derive from this. We want to be able to maintain both sites by editing the same code.
So we don't have to edit simple changes in both projects.
The difference between the sites, are the css file(and maybe the master page).
And some dependant code, like f.ex. login.
I figured I could do this using different build configurations.
First of all:
Is this a good way to solve it?
If yes:
How do I create a web.config file to load a different settings?
How do I load different css file(and different master page).
How do I create dependent code?
If no:
What would be?
Thanks for any help and tips contributed.
The css files you can change it on application_start event (assuming that you have two different host for the application).
You can change the master page at preInit event of page.
The better approach can be
Create you business logic in a separate project.
Try to create different Theme for different Client.
Set the theme on Application_Start event.
You can also take advantage of DI (dependency injection) to call different method of different classes.
You would be better off creating two projects, but creating shared code as a dll that both projects can share.
I've worked on custom web CMS and therefore i have to create two websites doing some common functionalty. Here are my steps
Create a solution.
Add a class library type project
Add two different websites
Give reference of class library to both websites and you are good to go.

Add files to existing project programatically using C#

I am currently developing a solution that has two projects on it: one is some kind of API where I put all the functions that I want to use in the second.
So, at some point in the project, I need to create a file programatically. This is ok, but I need to include that file in my second project to use the functions from the first projects! Any idea on how to do this?
I have tried the EnvDTE but I think it only works if you are creating a new solution and a new project.
Really need help on this! Thanks in advance! :)
Are you literally trying to recompile the second project after creating these files or is this all happening at runtime?
To me it sounds like what you're trying to do is really not create a file but to emit a class in memory during runtime to make new functions available to the second executable. You should check out Reflection.Emit. That is how you define classes, even assemblies, that didn't exist when you started running the program. Check out MSDN and this code project article.

Want to install same application but with different name in WP7

I have an application lets say "Application1" .I want to install same application but by changing some contents in it and also its name like "Application2" so that both application1 and application2 can be seen on device?
Is this possible?If yes,then can someone kindly help as to how to do it.
EDIT:
Just if somebody else might need it, I got this done.
Get a GUID from a GUID generator tool and use this new GUID in WMAppManifest.xml and replace ProductId in this file and GUID in AssemblyInfo.cs.Rebilud the solution and its done!
Creating a new app with exactly the same content is very easy:
Create a new project and name it with the new name.
Remove the pages/classes created by default in the new project.
"Add as Links" all the pages/classes from the original project.
If you want to have different content in the second app, just put the different content in a separate file and use that rather than a linked one. (Partial classes split across multiple files make this very easy.)
Another way to customize content in the second app is to define a partial method in the original app but only implement this in the second app (in a partial class/file which only exists in the second app). In the implemented partial method add your changes to override the default (original app) behaviour/layout/whatever. - This is a good way of altering pages where you don't want to have to put customization into an already existing app. You just "override" it in the second app.
You would need to submit the two slightly different applications to the market as separate applications in order for them to be seen on the user's device.
As Matt suggests, if the two applications have a lot in common, then you can use linked files to reduce your maintenance overhead.
In addition to Matt's suggestion, I've done this for Free/Paid versions of the same app.
It's pretty easy to do. The files to change between versions are:
the icons
the splash screen
the mobile XML file in the Properties folder
The important thing in the XML file is the GUID identifying your app. This GUID doesn't seem to be used in the Marketplace - but it is used by the debugger's deployment functionality.
You can also use a project level #define to include/remove any other code you want different between the projects.

ASP.NET Web User Control Library

We have a bunch of user controls we would like to pull out of a web application and into a separate assembly/library, and I thought it would be as simple as creating a class library and pulling the ascx and ascx.cs files into the project, and compiling a DLL to be reused among our applications.
This was not the case, however.
Our ultimate goal is to have a single distributable DLL (similar to how Telerik distributes their controls) that we can throw into any web application. The steps here: Turning an .ascx User Control into a Redistributable Custom Control were very simple to follow, however this results in many files named controlname.ascx.guid.dll, which is not the desired result. I couldn't even get these to work anyways, since we have additional classes that need to be compiled into the assembly.
Has anyone successfully created a web user control library in .NET (we're using 3.5 here)? I can't seem to find a nice step-by-step guide.
I realize this is an old topic, but if anyone is looking for a solution for creating reusable user control libraries, it turns out it's fairly simple. Here are two good step-by-step guides along with source code:
From MSDN: Turning an .ascx User Control into a Redistributable Custom Control
From Code Project: Straight way to create ASP.NET user controls library
The second link provides a solution to the multiple dlls created by the first link.
Edit- (2) Seems to be a dead link. Here's the new link
https://www.codeproject.com/Articles/30247/Straight-way-to-create-ASP-NET-user-controls-libra
If you want to share controls among project, my experience has shown that the best way is to build custom asp.net server controls instead of usercontrols. User controls are good for sharing within the same project, but not over multiple ones.
For this purpose I suggest you to build a set of custom server controls inside a class library and use that on all of your projects.
This book does quite a good job at explaining the basics of creating server controls
Edit:
I'm currently developing a .net web server control library. I actually didn't follow any step-by-step guide. I mostly considered using the book I mentioned above and the MSDN library + Reflector, which is a great tool for inspecting existing MS server controls and learning from them.
I found the tutorial Creating and Using User Control Libraries but it seems like a bit of a hack as it relies on a post-build command line event to copy the user controls from one project to another.
Somewhat late, I admit.
To create a re-usable library of user controls; create a new Web Application Project, delete all the scaffolding, add a (number of) user control(s). Create a Web Deployment Project from the Web Application Project, in the WDP properties choose the option to Merge all control output and assign a name for the library and ensure that Allow this website to be updatable is NOT checked.
Build the WDP and use Reflector to examine the generated library; you'll see that it contains an ASP namespace and the types you carefully crafted have been renamed i.e. usercontrol_ascx. In your target website(s) add references to BOTH the output dlls from your WDP, add a system.web/pages/controls node to web.config using the namespace ASP and the name of the assembly that you defined in the WDP.
Now when you use the library in a page (for example) you must use the alias that you defined in web.config and the typename as seen in Reflector i.e.
<ucl:usercontrol_ascx ... />
I found it useful to add a dependancy for the website(s) on the WDP so that the WDP is built before the websites; now I can change the user controls in the WAP without having to remember to build the WAP before building the website(s).
I hope that someone finds this useful as it cost me a few grey hairs getting to this stage and still have VS do its 'automagically' thing.

Categories