This project is read-only.

Convert to a web app

Dec 30, 2008 at 1:13 AM
I would like to conver the problem from a file based app to a normal web app in the VS editor.  There are a couple reasons for this.  Anyway, I created a new project any copied all of the files into it.  After receiving numerous errors regarding WidgetBase, I found that I forgot to run the "Covert to web app" on the project.  So I did that.

After that I found that VS was complaining about redeclarations.  It seems that some of the modules (Like TextBox/edit.cs) are using duplicate class names.  It appears to be a cut/paste issue.  So I figured I'd bring this up as a problem as anyone trying to precompile this might run into some class issues.  The final show stopper for converting it to a VS web application is that it can't find some of the controls on the web site since they seem to be loaded dynamically.

Anyway, I was wondering if there is a particular reason for using the file based web site versus a web project? 

I did read another thread relating to the same question, but it seemed to be answered by someone saying that works, but not confirming how they got it to work with as a web application (or they didn't understand what the question was).

Any suggestions on this would be great.
Jan 1, 2009 at 7:40 PM
Hey Gary, sorry I do not have a solution for you but I couldn't help but laugh at your first sentence, "I would like to conver the problem...". I asssume you meant project or the antonym, solution. Anyway thanks for the smile and have a Happy New Year!
Jan 2, 2009 at 4:45 AM
Wow.  Typo.  I'm usually pretty good about that but I had a compressed week (32 hours in 3 days) so I was working on caffine.  so -e 's/conver /convert /g' -e 's/problem /project  /g'.  Hopefully that's a little clearer.  Anyway, thanks for the feedback.  Thus far its been a pretty good year though I'm only ~20 hours into it.

Jan 16, 2009 at 12:29 PM
Hey Gary,

I have the same problem to convert the website but I don't understand what you've done. Can you explain with more details please


Feb 12, 2009 at 1:47 PM
I tried following the instructions on this MSDN page for converting a web site to a web application, however I still encounter the above errors with invalid WidgetBase references and duplicate filenames in the same namespace.

Could it be because during the "Convert to Web Application" phase the conversion of some of the files/controls generates error messages and that's why the subsequent step of pulling the code out of the App_Code folder into the main folder still does not work to resolve the references issue with finding WidgetBase?

Also how do we really deal with the duplicate filenames issue?  Widgets are not created by inheritance in the best possible sense, the widget files NEED to be named widgets.ascx and edit.ascx in order for the widgets framework system to work. Was this an oversight in design of the framework? Or is there some way to overcome this issue and actually (finally) get BlogEngine.Net to run as a ASP.Net Web Application project?

Feb 12, 2009 at 5:38 PM
I haven't worked with a WAP project for a bit, but I don't think there's a problem with having duplicate file names.  As long as the files are in different folders, the class names are unique and the ASPX pages point to the correct codebehind file, then things should be okay.

What version of BE are you trying to convert to a web application?  I ask because as Gary mentioned, the Textbox widget's edit.aspx.cs has a class name of widgets_LinkList_edit and so does the Linklist's edit.aspx.cs (duplicate class names aren't allowed in WAP).  In the latest build of BE, the class name in the Textbox's edit.aspx.cs file is correct, widgets_TextBox_edit.

There might be some other files like this too ... I haven't looked myself.
Feb 12, 2009 at 5:46 PM
Hey Ben,
I'm trying to convert a customised version based on the latest release of the code (BE 1.45 is it?)

If you do try to do this yourself (convert the web site available in the (source) download to a web application project) and succeed I'd really like to know which step I went wrong at or which modification I needed to make to my approach...for now though, I'm chugging along with the Web Site version...

Feb 12, 2009 at 6:04 PM
Maybe later I'll have some time to try a conversion.  I haven't tried it yet just because the web site version has worked well for me.

When I say the 'latest build', I'm talking about changeset 24796 available for download on the Source Code tab above.  Version 1.4.5 came out in August ... where changeset 24796 just came out February 1st.  There's been lots of changes and improvmenets since 1.4.5 was released.  The next 'official' release will be 1.5 and is supposed to be in the near future.

Also, thinking back on this more, I'm sure you're allowed to have the same filename more than once in a WAP project.  I have some web site projects that used to be WAP projects that have files with the same name.  Usually Visual Studio will tack on a number at the end of a class name if the class name already exists.  Like 'public class index', then 'public class index2', 'public class index3' ... but all 3 files are named index.aspx -- they're just in different folders.

It's sort of funny that we're talking about a WAP conversion of BE because I just read this recent blog entry from the MS web development team where they converted BE into a WAP project!  Their blog isn't focused on the conversion process, but they didn't mention any problems.  Maybe that was because they were using VS 2010 and it might have a better WAP conversion tool ... not sure though.  Either that or they did have conversion problems, but didn't talk about the problems in this particular blog entry.
Feb 14, 2009 at 8:24 PM
I was able to convert BE 1.4.5 into a web application project (WAP).  It took some trial and error, but I've documented the steps I did below.  I did this with Visual Studio 2008 and BE 1.4.5.  If you try this and have problems, best thing to do is look at what error message(s) Visual Studio gives you to fix the problems it finds.

 1. Create a new WAP.  File -> New -> Project -> Visual C# -> ASP.NET Web Application.  Select the location (I created a new folder for this WAP project), and I used 'BeWap' for the Name of the project.
 2. Close Solution.
 3. In Windows Explorer, copy all the BE files into the WAP folder.  You'll be overwriting a couple of the files that were included in the new WAP project we created (default.aspx and web.config and maybe a couple of others).
 4. Rename the App_Code folder to Old_App_Code.
 5. Reopen WAP solution in Visual Studio.
 6. Right-click on project name (BeWap) in Solution Explorer, and select 'Add Reference'.  Go to the Browse tab, and browse to the BIN directory in this project, select 'BlogEngine.Core.dll'.
 7. In Solution Explorer, click the 'Show All Files' icon.  All the files/folders that we copied into the WAP folder will show up in Solution Explorer, but they are not yet included in the project, so they are white/ghosted out icons.  Select all these 'excluded' folders/files in Solution Explorer, right-click and select 'Include in Project'.
 8. Select the top node in Solution Explorer, 'BeWap' (right under Solution 'BeWap').  Right-click and select 'Convert to Web Application'.
 9. Save all files (Ctrl-Shift-S).
 10. In the web.config file, in the <pages> section, there's this line:
    <add namespace="Controls" tagPrefix="blog"/>
    Change that to:
    <add assembly="BeWap" namespace="Controls" tagPrefix="blog"/>
    ... where "BeWap" is the name of this WAP project.
 11. The site.master files for Indigo, Mobile and Standard all have the same class name of 'site'.  Change the class name in site.master.cs for the Standard theme to site_standard and changed the Inherits attribute in the <%@ Master %> directive in site.master to site_standard (so they match).  Need to do the same thing for the Indigo and Mobile themes ... giving them class names of site_indigo and site_mobile.
 12. The class name in edit.ascx, edit.ascx.cs and edit.ascx.designer.cs files in the RecentComments widget is widgets_RecentPosts_edit.  Need to change the class name in these 3 files to widgets_RecentComments_edit.
 13. The class name in edit.ascx, edit.ascx.cs and edit.ascx.designer.cs files in the TextBox widget is widgets_LinkList_edit.  Need to change the class name in these 3 files to widgets_TextBox_edit.

 14. The class name in widget.ascx, widget.ascx.cs and widget.ascx.designer.cs files in the TextBox widget is widgets_LinkList_widget.  Need to change the class name in these 3 files to widgets_TextBox_widget.

 15. Save all files (Ctrl-Shift-S).
 16. When trying to build the project, I was getting about 47 errors about unrecognized controls.  The problem was the 'designer.cs' files didn't get created for these ASPX pages back in step 8 when I did the 'Convert to Web Application' command.  Even if I try repeating that step again, the designer.cs files still do not get created.  Visual Studio is complaining that various BE controls (blog:SearchBox, blog:PageList, etc) are unknown server tags.  If Visual Studio can build the project once, then these BE controls will start to get recognized.  What I did to get this done was temporarily exclude these pages that reference the BE controls.  The pages referencing these controls can be found in Visual Studio's error list when you try to build the project.  I excluded the entire Widgets folder, the entire themes folder, the post.aspx file, the error404.aspx file, the default.aspx file and the api\TagMiniView.aspx file.
 17. Build the solution.  Should get no errors.
 18. Add those temporarily excluded items back into the project from two steps ago.
 19. Select the top node in Solution Explorer, 'BeWap' (right under Solution 'BeWap').  Right-click and select 'Convert to Web Application'.  The pages we re-included back into the project should now all have designer.cs files.
 20. Build the solution.  Should get no errors.
 21. Run the solution.  Everything should work.
Feb 16, 2009 at 8:30 PM
Thanks for the step-by-step guide Ben!
It totally worked! Now I can move on to building the Amazon S3 image and file storage feature for BE.Net I mentioned I wanted to take a stab at.
Sep 9, 2009 at 9:56 AM

Thanks it works great.

Maybe an update for the BE 1.5 the point 12,13 and 14 can be skipped.


Jun 1, 2010 at 6:29 AM

I tried this in VS2010 / 1.6.1 and none of the extensions work.  Has anyone else had this problem and resolved it?

Jun 2, 2010 at 5:13 AM

I think it's more of a problem with IIS7 and how it loads extensions using the Global.asax file. Instead, you can pre-compile your extensions like this site displays and you should be fine.

Jun 2, 2010 at 7:02 AM

Its a bug in the Utils.CodeAssemblies method.  It never gets to the GetCompiledExtensions call because the if doesn't wrap the codeAssemblies.Add line in the code below.  This will always result in FileNotFoundException on non-mono systems.  I doubt extensions will work for anyone with a WAP project as they can never be loaded.



					Type t = Type.GetType("Mono.Runtime");
					if (t != null) assemblyName = "App_Code";
Jun 3, 2010 at 5:34 AM

I have a web application project and I use compiled extensions just fine. It doesn't run the lines of code you listed above unless it has to (ie; you are running on a mono system). If you have a .dll in your ~/bin dir with the proper attributes on them, that has the highest priority on loading extensions :-)

Jun 3, 2010 at 5:39 AM
Edited Jun 3, 2010 at 5:57 AM

I have the proper assembly attributes set, but it never even gets to that part of code to look for them because GetCompiledExtensions is never executed.  Try stepping thru it with the debugger - you will see it it always goes into the else statement regardless of if you are running on a mono system or not.  There is another post on the forum about someone else having the same issue, so its not just me seeing this behavior.  I pasted in the code below where the issue lies.  In my case s.CodeSubDirectories.Count is zero so it falls into the else.    And since the mono type is null it tries to load an assembly named "__code".  That results in a file not found exception, thus GetCompiledExtensions is never executed.  GetCompiledExtensions does work correctly.   

public static ArrayList CodeAssemblies()
			ArrayList codeAssemblies = new ArrayList();
			CompilationSection s = null;
				string assemblyName = "__code";
					s = (CompilationSection)WebConfigurationManager.GetSection("system.web/compilation");
				catch (System.Security.SecurityException)
					// No read permissions on web.config due to the trust level (must be High or Full)

				if (s != null && s.CodeSubDirectories != null && s.CodeSubDirectories.Count > 0)
					for (int i = 0; i < s.CodeSubDirectories.Count; i++)
						assemblyName = "App_SubCode_" + s.CodeSubDirectories[i].DirectoryName;
					Type t = Type.GetType("Mono.Runtime");
					if (t != null) assemblyName = "App_Code";

			catch (System.IO.FileNotFoundException) {/*ignore - code directory has no files*/}

			return codeAssemblies;
The change I made to fix the issue is:
if (t != null) 
assemblyName = "App_Code";
Jun 4, 2010 at 12:57 AM

For the GetCompiledExtensions to work, the AssemblyConfigurationAttribute of the web app should be "BlogEngineExtension"

Code from Utils.cs

AssemblyConfigurationAttribute aca = (AssemblyConfigurationAttribute)attr[0];
if (aca != null && aca.Configuration == "BlogEngineExtension")

I am not entirely sure why it is looking for a configuration attribute instead of a specific attribute. I changed the AssemblyConfigurationAttribute of the webapp and the extensions are up and running again. For my build though, I might end up using a custom attribute.

Jun 4, 2010 at 4:28 AM
bytemonger wrote:

I changed the AssemblyConfigurationAttribute of the webapp and the extensions are up and running again.

You might want to compile extensions into separate DLL to speed things up a little. Not a big deal as main DLL is relatively small and going through reflection on app start is not a performance killer, but would be cleaner. This feature was added to support compiled extensions but will do for web app too.

Jan 28, 2011 at 5:55 PM

Anyone know how to convert BlogEngine v2.0 into a web application?

Many thanks

Jan 31, 2011 at 1:11 AM

As a side effect of needing to work with Monodevelop. I converted BE 2.0 to a WA

The source (pre Mono-Monodevelop, for VS2010) is here:

I had to do some extensive changes in order to get BE to realize that now there was a built assembly from the beggining so probably some stuff does not work (like checking extensions code)

I hope it helps you somehow.

Feb 1, 2011 at 3:24 AM

This fork is latest BE 2.0 code converted to web application (also to .net 4.0). Extensions are in the Custom_Code folder and everything seems to be working fine. I'll try to keep it in sync with main code as much as possible. Let me know if you try it and have any issues.

Feb 1, 2011 at 1:51 PM

Great! I will check the fork. I am mainly interested in keeping BE running smoothly on Mono and being able to work on its code with Monodevelop. I'll let you know if I see something that could be improved towards compatibility.

Feb 5, 2011 at 7:24 PM
Flaker wrote:

Great! I will check the fork. I am mainly interested in keeping BE running smoothly on Mono and being able to work on its code with Monodevelop. I'll let you know if I see something that could be improved towards compatibility.

Just got it fully functional under Monodevelop. I'll do a post and share code soon.

Feb 5, 2011 at 10:21 PM

Added to documentation section on conversion to Web App with a link to the fork from where you can download converted version

Feb 21, 2011 at 4:42 PM

Using the converted project and following the setup instructions i get a server error:

Parser Error Message: Unknown server tag 'blog:PostPager'.

I get this running under 3.5 or 4.0.  Anybody ever seen this?

Feb 21, 2011 at 4:57 PM

Fixed unkown server tag


8. In the web.config file, in the "pages" section, change from:

<add namespace="App_Code.Controls" tagPrefix="blog"/>


<add assembly="BlogEngine.Net" namespace="App_Code.Controls" tagPrefix="blog"/>

as defined at:
SQL web.config files must not have been updated to reflect this build.
Mar 29, 2011 at 6:22 PM

I have tried Fork for WAP. For some reason the web app code does not match with Core assembly code. I think the assembly included with the project may match with what the converted web app is.  But sure it does not match with latest source code with whats there for main branch. So ended up creating my WAP conversion and posted on my blog.

BlogEngine.Net WAP Converted projects