What part of web site to be WSP / WAP? - c#

I'm new to ASP.NET, and would like an understanding of when/where to use WSP vs WAP.
I will make a rather simple business website, with 6-7 pages, where one page will open a registration/login form where the user can see various personal data and reports, pulled from a database.
Would this suggest the use of a combination of WSP and WAP, where for example the login window is part of the WSP, and a successful login opens a WAP in a frame or in a new browser window/tab?

mmhh you are confused with the notion of web application and web site.
You cannot make one page in one way and another the other way, because WAP and WSP are type of project. So it is at the beginning of your project in visual studio to decide which one to use.
Basically, WSP is leaving the compilation of your code to IIS, and so you are working only with files. Using WAP, your project behaves like in a normal application, Visual studio will then compile your code to create different dll. You will then have only to move to your production environment the page aspx and the dlls, whereas with WSP, you would also include aspx.cs.
this link will tell you everything you might want to know
hope it helped,

Related

How do I integrate a new MVC C# Project with an existing Web Forms VB.NET Web Application Project?

We have a corporate website with a large amount of dynamic business application pages (e.g. Shopping Cart, Helpdesk, Product/Service management, Reporting, etc.) The site was built as an ASP.Net Web Application Project (WAP). Our systems have evolved over the years to use .NET 4.5 and various custom business logic DLLs (written in a mix of C# and VB.NET). However, the site itself is still using VB.NET Web Forms. We now have done a few side projects in MVC 4 using Razor/C#, and we want to use this framework for new pages on the main corporate site going forward. What would be the easiest way to achieve this?
I found this nice list of steps to integrate MVC 4 into an existing Web Forms app. The problem is that because our existing app is a VB.NET WAP, it compiles into a single DLL, and .NET allows only one language per DLL. The site is way too big for us to contemplate converting it to C# all at once (yes, I've looked at the conversion tools, and they're good, but even 99% accuracy would leave us a huge amount of cleanup work.)
I thought about converting the existing WAP into a Web Site Project (WSP) which does allow mixing languages and then following the steps above, but after a few pages of Google results, I couldn't find any steps for converting a WAP to WSP. (Plenty of sites offer the reverse steps: converting a WSP to a WAP.)
Another idea I had was to create a completely separate MVC project, and then somehow squish them together into the same folder structure, where they would share the bin folder but compile to separate DLL's. I have no idea if this is possible, because certain files would collide (e.g. Global.asax, web.config, etc.)
Finally, I can imagine a compromise solution where we keep all the MVC stuff in its own separate application under a subfolder of the main solution. We already use our own custom session state solution, so it wouldn't be difficult to pass data between the old site to the new pages.
Which of the ideas above do you think makes the most sense for us? Is there another solution that I'm missing?
After some more research and experimentation (and thanks to a suggestion from T.S.) I have narrowed it down to either the 2nd or 4th option from my initial question:
Convert our WAP to a WSP, and then follow the steps to integrate MVC into the site. I don't see moving from a WAP to a WSP as a complete step backward. As the MSDN link explains, performance does not suffer, and it's mainly a question of how to adjust our build/deployment process. The major advantage with this technique is that it allows multiple languages to coexist in the same project and root folder. Certain files, such as Global.aspx.vb, would have to remain in VB.NET. But specific folders and web pages could be designated as C#. The disadvantage for us is that our site has a lot of legacy pages that use old-style server-side-includes of ASPX page fragmets, and these cause build errors in a WSP. These would have to be changed into User Controls, or perhaps renamed to an unrecognized extension, such as .aspxinclude, so that they are not included in builds.
Create an MVC child application as a new .NET project (see http://support.microsoft.com/kb/307467). The parent web.config needs its <system.web> section wrapped with <location path="." inheritInChildApplications="false">, and the new app's subfolder needs to be converted to an Application via IIS Manager. The child app can be a WAP using a different default language (C# vs VB.NET). This makes it is easier to isolate from our existing project. But this is also a disadvantage because the MVC routing only works on URL's in the subfolder of the child application. So if we wanted multiple parts of our site to use MVC routing, it would require separate child projects, e.g. (/cart, /myaccount, etc.)
We are probably going to go down the path of option #1, converting to a WSP, and only resort to #2 if we encounter a big obstacle.
UPDATE: I was able to do the conversion using technique #1. It's been working for several months now, so I published a blog post with the procedure I followed.
Came up with a very simple solution.
Create new MVC C# project
Add the old vb project to the solution.
Move the VB aspx pages to the new C# project
REMOVE THE CODE BEHIND ATTRIBUTE FROM THE FIRST LINE OF THE VB PAGES eg...Codebehind="ProductDetails.aspx.vb" (this is the magic)
Add a reference to the VB project in the C# project
This will work for master pages as well
Strangely the VB aspx pages 'just find' the codebehind from the reference and the C# project does not seem to care about the aspx pages being VB.
Go figure!
Hope I saved someone some time. I spent many hours on this.
You have 3 options here:
Convert the ASP.NET Web forms from VB to C#
Convert your MVC 4 written in C# to VB.
Develop all old apps in ASP.NET Web forms again to MVC 4 (ugly but better for future changes)
My advise is keep them diferent projects only share your business logic. And in the same solution file.

Application getting slow when open the application for the first time

I have developed a application in ASP.NET using c#. The entire application working fine but the problem is when I open the application for first time it running very slow. i.e. its taking so much time to load a page like home page or any other page. But when I reopen that page then that page opens quickly as I expect. Even whenever application getting session expired and relogin into application its taking so much time again to load all the pages for the first time, where from 2nd time to opens that pages its not happening. So can anybody tell me what is the problem occuring here.
The application is compiled on the first request.
Read this article by Microsoft.
Because ASP.NET compiles your Web site on first user request, you can
simply copy your application's source code to the production Web
server. However, ASP.NET also provides precompilation options that
allow you to compile your Web site before it has been deployed, or to
compile it after it has been deployed but before a user requests it.
Precompilation has several advantages. It can improve the performance
of your Web site on first request because there will be no lag time
while ASP.NET compiles the site. Precompiling can also help you find
errors that might otherwise be found only when a user requests a page.
Finally, if you precompile the Web site before you deploy it, you can
deploy the assemblies instead of the source code.
You can precompile a Web site using the ASP.NET compiler tool (ASPNET_Compiler.exe). The tool that provides the following precompilation options:
In-place compilation This option performs the same compilation that occurs during dynamic compilation. Use this option to compile a Web site that has already been deployed to a production server.
Non-updateable full precompilation Use this to compile an application and then copy the compiled output to the production server. All application code, markup, and UI code is compiled into assemblies. Placeholder files such as .aspx pages still exist so that you can perform file-specific tasks such as configure permissions, but the files contain no updateable code. In order to update any page or any code you must precompile the Web site again and deploy it again.
Updateable precompilation This is similar to non-updateable full precompilation, except that UI elements such as .aspx pages and .ascx controls retain all their markup, UI code, and inline code, if any. You can update code in the file after it has been deployed; ASP.NET will detect changes to the file and recompile it. Note that code in a code-behind file (.vb or .cs file) built into assemblies during precompilation, and you therefore cannot change it without going through the precompilation and deployment steps again.
However, you mentioned that it's also slow if the session expired. Maybe you are loading too much into memory on session start. It's difficult to make a diagnosis without more informations.
Check your site in firebug in .net tab there you will find which part of your page take much time to load,
there might be some exceptions or some code errors in client side language.
Try to use less sessions
and debug your code to clarify no extra looping of code
(sorry for bad English but hopefully you have got my point)

Protect source code of an ASP.NET website

In our college they have competition--students have to develop and show some code. It has a cash prize. I have done an entry as a website (C#) using asp.net. The problem is that my website is in the computer laboratory of the college, so anybody can open Visual Studio and copy my project or edit it.
I want to protect my project. Is there any way to put password for the project alone in Visual Studio? To make it attractive I have hosted the website in the IIS of the server, so by using the IP adresss I can run the project anywhere with intranet access.
When I put a lock like EasyFileLocker, I am unable to open and run the project using the IP address.
I want to run my project anywhere in the intranet, but also protect its code.
How can I do that?
Presuming your source code is somewhere safe (if not, then put it somewhere safe over which you have control), then the deployed end result need not expose the source code in its raw format; you can pre-compile ASP.NET websites entirely (such that even the markup can't be edited on the server - at least not very easily) - do this by selecting the pre-compilation options on the deploy screen, being sure to uncheck "allow this website to be updatable".
the exact method of specifying the right build options differs between VS versions, but the options are the same ultimately: Precompile, (Don't) Allow precompiled site to be updatable.
The result is the code of your website ending up in binaries, including the page markup (the files still exist, but simply as placeholders with their substance missing.) For someone to get at your code, they'd need to reflect your binaries.

website - compile classes -update in the server

I have created a website using ASP.Net and running on port 8080. When server is still running, I can some changes in the code. Interestingly, those changes are reflected on my site when I pressed refresh button. I just wondering with this because I guess we have to compile and rebuild site to see new changes.
thanks !
Yes, WebSite working in this way. WebApplication requires rebuild all because all codebehind logic are built in DLL of WebProject
See this MSDN article: Comparing Web Site Projects and Web Application Projects
Web Site Projects
Prefer dynamic compilation and working on pages without building entire site on each page view (that is, save file and
then simply refresh the page in the browser).
That depends on if you have an asp web site of a web application. Take a look at this msdn page for more info.
When you have the full source for an ASP.NET web site (not a web application) running, your site will be dynamically compiled, and changes you make will be detected.
From the MSDN documentation, Understanding ASP.NET Dynamic Compilation:
Any changes to a dynamically compiled file will automatically invalidate the file's cached compiled assembly and trigger recompilation of all affected resources. The next time a request to the code is made, ASP.NET recognizes that the code has changed and recompiles the affected resources of the Web application. This system enables you to quickly develop applications with a minimum of compilation processing overhead. (Note that depending on the change to the resources, the result can range from recompiling a single page to recompiling the whole Web site.)

How do I compile and run an ashx file in visual studio?

I have
an ashx file,
Visual Studio 10,
no knowledge at all about C# ASP.NET
What is the proper way to compile and run this?
Context
The ashx file in question can be found in this zip, and is a demo application for a Tetris AI competition. It is a very enticing idea even if it depends a great deal on luck, and I thought I might use the occasion to learn a new language.
An ashx file is a just a generic HTTP handler, so the easiest way to get this working is to create a new Web Site in the File menu, and just add the Handler.ashx file to the website root directory.
Then, just run the site (F5) and browse to "YourSite/Handler.ashx".
An ASHX file is like an ASPX file, but it's a handler. That means it doesn't respond back with HTML by default, and can therefore "handle" otherwise unhandled file types, but it's not necessarily tied to that meaning. In this case, you'll only be presenting the response
position=8&degrees=180
...to a posted board and piece. So you don't need HTML, so you want an ASHX.
You can make .ashx files the startup page in your project, just the same as .aspx pages. If I were writing a HelloUser.ashx page, I might set it as the start page, with some parameters passed in as querystrings or something.
You're probably going to want a test harness that posts a board / piece to your service, and that could be any kind of project. Command line program, website, test class run through NUnit, whatever. There's a lot of logic to keep track of beyond the "player" logic.
If you need a more detailed answer than that, SO might not be the place for this question. But I wish you all kinds of luck with this - it's an interesting problem.
You need to deploy it to an IIS server that has the proper .NET framework installed and that should be it.
If you are trying to get it working locally, create a web site project in visual studio, go to "add existing items" in solution explorer, and locate your ashx. Then click the play button (or press F5) to compile and run it.
Good luck!
You're missing an some form (an ASPX file maybe) that goes with this handler. It looks like this thing probably handles some AJAX request from another page.
It's expecting 2 pieces of data with the request as well:
string board = context.Request.Form["board"];
string piece = context.Request["piece"];
You could reverse engineer the form that this is for, but it will probably take some time to get that board array right.

Categories