Why can't you build a website in release mode? - asp.net

In ASP.Net, if I set up a web application I can configure it to be in release mode but with a website I can only set the configuration to be in debug mode. Why is this?

In web site projects each page is compiled dynamically upon first request. It will compile without debugging symbols unless you specify otherwise in the config file.

A Web Site's debug/release is controlled by the Web.Config file:
<system.web>
...
<compilation debug="true">
...
</compilation>
</system.web>
Set debug="true" for debugging, set debug="false" for release.

Probably because a Web Application compiles the whole website into one DLL. To run and debug pages requires recompiling the entire application. Whereas a website project compiles dynamically at the page level.

For websites one releases the source code to the site, there is no build to be done.
The code is built on site.

Related

Why my MVC views are compiled with PDB?

Now this is interesting!
I just noticed that exceptions in my MVC Views have line-numbers in the stack trace! Which means - my views are compiled with PDB.
I looked at the "Temporary ASP.NET Files" folder on my server - and yes, there are PDB files for every view.
I have <compilation debug="false"/> in my web.config.
Why is this happening and how do I disable that? This is the production server, so I would like to disable the pdb-generation.
I checked my "web.config", "Views/web.config", "machine.config", default "web.config" in windir%\Microsoft.NET\Framework64\[version]\config\ - I think I haven't found any suspicious compiler options there... Where do I look?
Or am I just wasting my time and this is the default option that cannot be changed?
PS. More info, just in case: this is an MVC 4 app, the Views are written in Razor.
Found it!!
Seems like this is the default setting for Razor - it is always compiled with DEBUG option and you can't change it - but I think I found the solution.
Adding this to your machine.config seem to fix the issue:
<configuration>
<system.web>
<deployment retail="true"/>
<system.web>
</configuration>
At least I don't see any more .pdb's in my "Temp ASP.NET Files".
More info about this flag on ScottGu's blog: http://weblogs.asp.net/scottgu/Don_1920_t-run-production-ASP.NET-Applications-with-debug_3D001D20_true_1D20_-enabled

Is there a "release" configuration for ASP.NET Web Sites?

I use Visual Studio for Website development (VS 2010 Ultimate and VS 2012 Professional). To be more specific, I created this website by File > New Web Site, so I do not believe this is a project.
While developing the website, I have debug="true" enabled in the web.config file. When I publish, I manually change to debug="false".
<configuration>
<system.web>
<compilation debug="true" strict="true" explicit="true" targetFramework="4.5">
</system.web>
</configuration>
There are two config files in the solution: "web.config" and "web.Debug.config".
This is what the various forum articles and "Programming ASP.NET" books say to do, but I wonder if there is a way to have debug="true" for local development and automatically switch to debug="false" when using Build > Publish Web Site so I don't have to manually change the web.config file?
According to this forum answer, "There is no way to have a Release configuration for your website."
Keeping in mind that this is a Web Site and not a project, it looks like adding another config based on comment suggestions might not be possible. A possibly valid answer is "no, it is not possible in this context."
Is there another way to achieve the intended outcome without using the current workaround of manually changing the debug setting?
Sorry, it's related to it being a "web site" type project, which aren't compiled:
Configuration of publishing an ASP.NET web site
To quote the previous responder above:
"Web Site projects don't have the Release configuration available, but it makes no difference since they are not compiled. Web Application projects, on the other hand, do get compiled and have both configurations available."
According to the available references, for "ASP.NET Website" it is not possible to have a separate release configuration.
So the answer to the posed question is no: it is not currently possible. Manually changing the debug attribute when you publish and then changing it back is the only option in that case.
How can you proceed? If you really need to have a release configuration and a debug configuration, the a possible option is Converting a Web Site Project to a Web Application Project. While not a direct answer to the presented question, it is an alternative.
For some projects I've set up an Environment appSetting and scoped all other keys off of that Environment.
For instance:
<add key="Environment" value="Development"/>
<add key="Development.Title" value="My Dev App"/>
<add key="Production.Title" value="My Production App"/>
<connectionStrings>
<add name="DbContext.Development" connectionString="Initial Catalog=DatabaseDev;...."
providerName="System.Data.SqlClient" />
<add name="DbContext.Production" connectionString="Initial Catalog=DatabaseProd;...."
providerName="System.Data.SqlClient" />
</connectionStrings>
Then you would create a Configuration class that would pull appSettings and connectionStrings by looking for:
appSetting
string.Format("{0}.Title", ConfigurationManager.AppSettings["Environment"])
connectionString
string.Format("DbContext.{0}", ConfigurationManager.AppSettings["Environment"])
Not perfect but this will let you only have to replace one web.config value instead of a bunch without the help of the Publish config transform.

Adding System.windows.Forms reference into asp.net website

I have a asp.net application where i use System.Windows.Forms namespace reference to use web browser control.the application runs fine on local system but after hosting it shows error.
How do i embed the dll for to use in the web application.
Answering a 3 1/2 year old question is pretty weird...
I. In your web.config, add a reference to Windows.Forms
<system.web>
<compilation>
<assemblies>
<add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
</assemblies>
</compilation>
<system.web>
This only works if the referenced DLL is in the GAC. If it is not:
Create a /Bin folder in your website root.
Copy your DLL there.
Do not add a reference in web.config.
II. In your module/class, import Windows.Forms (VB: Imports / C#: using)
Imports System.Windows.Forms
You can now use the web browser control. It's a bit tricky, though.
Possible uses include: generating screenshots, AJAX crawling (#! >> _escaped_fragment_) etc
System.Windows.Forms contains classes for displaying things on the computer that the code is running on. When you are testing on your PC, it works because you run the browser on the same machine as your development server.
When running on a real server, anything in System.Windows.Forms would be displayed on the server - not on the user's PC. (Besides it would be displayed on a hidden desktop in the server's service session).
You shouldn't mix webforms and windows forms. Whatever you want to do - there is another way that works, that doesn't involve winforms.
Don't use System.Windows.Forms in webb applications
As previously mentioned, you cannot use WinForms controls with ASP.NET.
Use an iframe to show whatever page you're trying to display in the webbrowser control: http://www.w3schools.com/tags/tag_iframe.asp
yes, you can do it,just copy the
system.window.form
dll into your web Bin Folder
everything will work fine.

Migrate ASP from root to subdirectory

I'm in the process of converting an existing ASP website into PHP while retaining the ASP website as an older version. Since I'm not an ASP developer, I thought it would be simple as moving the contents of the root directory into its own directory that I've labeled as v1.0 so that the ASP version can be viewed by going to www.mysite.com/v1.0 while the new PHP version (v2.0) can be viewed by going to www.mysite.com
Herein lies the problem. Doing this causes flags all kinds of errors (all related to "Server Error in '/' Application. Runtime errors"). The best I can figure out is that the web.config file needs to be tweaked in the v2.0 directory. Can any of you ASP experts recommend a simple solution to make this happen? I would like to have an empty root directory if possible since the new v2.0 version will be in all PHP and want to "self contain" the ASP version within the v1.0 directory as much as possible.
Thanks!
After a bit of wrangling, finally figured out that I needed to set up v1.0 as its own application under the IIS control panel. Once that was done, then all the contents of the root directory could be moved over to the v1.0 sub-directory and viewed via www.mysite.com/v1.0 -- thanks to Sean! for his help!
Most Classic ASP pages use Server Side Includes, if the site is using a SSI such as:
<!-- #include virtual = "include-file.inc" -->
, then you will need to change all of these to be
<!-- #include virtual = "v1.0/include-file.inc" -->.
I assume that you are using IIS 7 or IIS 7.5, since you are not seeing the actual error, you will need to modify your web.config file.
<configuration>
<system.webServer>
<asp scriptErrorSentToBrowser="true" />
<httpErrors errorMode="Detailed">
</system.webServer>
</configuration>
Reference:
http://learn.iis.net/page.aspx/564/classic-asp-script-error-messages-no-longer-shown-in-web-browser-by-default/
Update
Since it now sounds like you are using ASP.NET, you would need to change your web.config as below to see the full error:
<configuration>
<system.web>
<customErrors mode="Off" />
</system.web>
</configuration>

ASP.NET App Debug: Breakpoint currently not hit

I want to debug a ASP.NET application (Custom IHttpHandler) with Visual Studio 2008 and IIS7.
I compile the source, start debugging (F5) and IE loads. But my breakpoint (in method ProcessRequest()) is disabled. I get the error:
The breakpoint will not currently be hit.
No symbols have been loaded for this document.
I have no idea about ASP.NET programming. Do i have to set anything in IIS?
The PDB files are there. I wanted to check the symbol load status of my DLL but I couldn't find it.
When I open "Debug->Windows->Modules" I can't see my DLL in the list.
Only Windows DLLs and assemlies from GAC and so on.
Am I missing something?
Visual Studio -> Debug -> Attach to process
w3wp.exe
More info here: http://www.codeproject.com/KB/aspnet/ProcessAttache.aspx
For the archive: a breakpoint is only activated, once the corresponding assembly was loaded in the process space. So in order to enable a breakpoint which was set on a code line inside a DLL, you must run your app to the place, where the DLL is loaded. The breakpoint will than get recognized by the debugger and ungrayed in VS.
The problem for me turned out to be that the Properties->Build->Optimize code checkbox had been turned on in the Debug configuration. Turned it off, rebuilt, and debugging worked as normal.
Have you registered the HttpHandler in the <system.web> section instead of <system.webServer>?
In web.config:
<system.web>
...
<httpHandlers>
<add verb="GET" path="MyHandler.ashx" type="MyHandler, MyAssembly" />
...
</httpHandlers>
</system.web>
See Also
UltiDev Cassini and
web.config
settings
HttpHandler in IIS7 and
Visual Studio 2010
Solved it.
I had to open a page with an specific file ending while debugging. As soon as I opened the right page my DDL loaded and the breakpoint activated.

Resources