Edit Connection String in code and save into web.config
I am building an installer for my CMS, AdvGenCMS. The first part is adding connection string and saves it into web.config. That is doable in C#. Just like the following code:
Code
Configuration config = WebConfigurationManager.OpenWebConfiguration("~"); | |
ConnectionStringsSection connectionStrSection = config.GetSection("connectionStrings") as ConnectionStringsSection; | |
string conntectStr = String.Format("data source={0};Initial Catalog={1};uid={2};password={3};Intergrated Security=SSPI",serverModel.ServerName,serverModel.DatabaseName,serverModel.UserName,serverModel.UserPassword); | |
if (connectionStrSection != null) | |
{ | |
if ( connectionStrSection.ConnectionStrings["AdvCMS.Data.Linq.Properties.Settings.AdvCMSConnectionString"] == null) | |
{ | |
ConnectionStringSettings setting = new ConnectionStringSettings(); | |
setting.Name = "AdvCMS.Data.Linq.Properties.Settings.AdvCMSConnectionString"; | |
connectionStrSection.ConnectionStrings.Add( | |
setting); | |
} | |
connectionStrSection.ConnectionStrings["AdvCMS.Data.Linq.Properties.Settings.AdvCMSConnectionString"].ConnectionString = conntectStr; | |
connectionStrSection.ConnectionStrings["AdvCMS.Data.Linq.Properties.Settings.AdvCMSConnectionString"].ProviderName = "System.Data.SqlClient"; | |
config.Save(); | |
} |
We can use WebConfigurationManager.OpenWebConfiguration("~") to get the whole configuration and then use config.GetSection("connectionStrings") to get the connection string section. Now, we can play around the connection string section freely.
HttpRequestValidationException in Request.Form
I am writing a CMS in C# and a html editor in the asp.net page. Therefore, I got some HTML code in Request.Form Object. Last night, I found the problem. I got HttpRequestValidationException when I save a html content. That is safe by rejecting any post variables has html code. So, I tried the used [ValidateInput(false)] in the controller, that is not working. Finally, I found I need to turn off that globally in web.config
Code
<httpRuntime requestValidationMode="2.0" /> | |
<pages validateRequest="false"> |
Please remember to use <httpRuntime requestValidationMode="2.0" /> for switching the validation mode into 2.0, unless just turn off validate request is not enough!
Entity Framework sounds better than LINQ to SQL
Recently,I did some researches for Entity Framework and LINQ to SQL. I found Entity Framework sounds better. It got better facilities. It can generate data tables from EDX and if the tables can generate the updated classes from the database. If you are using LINQ to SQL, you need to update manually. Entity Framework sounds a more completed ORM, LINQ to SQL is only a tool to translate the objects into SQL. But I think LINQ to SQL is more lightweight.
JSON in WCF
A lot of people know about WCF supports XML as the return response. Actually, it supports JSON. All you need to set ResponseFormat.
Code
[WebGet(ResponseFormat=WebMessageFormat.Json)] | |
[OperationContract] | |
public SessionKeyDTO Authenicate(string username, string password) |
And you need to set web.config
Code
<behavior name="AdvCMS.Services.Service2AspNetAjaxBehavior"> | |
<webHttp/> | |
<enableWebScript /> | |
</behavior> |
It needs <webhttp/>. That is easy!
The code is a part of our CMS, AdvGenCMS.
Our .Net CMS - AdvGenCMS
Recently, our Company(AdvanGeneration) have built a lightweight .Net CMS,AdvGenCMS. I did some researches for .Net CMS. The most of them have own their ORM and Dependency injection framework. That is very hard to adapt into a web development framework. Thus, we decided to build our own.
AdvGenCMS is very simple. Our ORM is ms entity framework. Moreover, we have not any dependency injection framework. Currently, it used a factory design pattern, but that can choose to add dependency injection framework on your choice. Lastly, it used ASP.Net MVC. All of them are very very standard Microsoft technologies.
I don't want to add any functions you don't need. I just needed the core functions. Our CMS should be as simple as possible.
It has a user management function:
Moreover, it has a page function. You can add the static content and access them via http://[server]/Content/[PageName]
Lastly, it uses tinymce to be a html editor.
Let's use AdvGenCMS to be your web development framework. It uses Apache License.



