62,046
社区成员
发帖
与我相关
我的任务
分享
private HttpHandlerAction GetMyAction(HttpHandlersSection section,string handlerName) {
foreach (HttpHandlerAction action in section.Handlers) {
if (string.Compare(action.Type, handlerName, false) == 0) {
return action;
}
}
return null;
}
public override string GetDesignTimeHtml() {
string type = "WebApplication1.WebCustomControl1,WebApplication1";
IWebApplication webApp = (IWebApplication)GetService(typeof(IWebApplication));
if (webApp != null) {
Configuration config = webApp.OpenWebConfiguration(false);
ConfigurationSectionGroup systemWeb = config.GetSectionGroup("system.web");
HttpHandlersSection handlerSettings = (HttpHandlersSection)systemWeb.Sections["HttpHandler"];
if (GetMyAction(handlerSettings, type) == null) {
HttpHandlerAction handler = new HttpHandlerAction("*.xpax", type, "*");
handlerSettings.Handlers.Add(handler);
config.Save(ConfigurationSaveMode.Minimal);
}
}
return string.Empty;
}
IWebApplication webApp = (IWebApplication)Component.Site.GetService(
typeof(IWebApplication));
var config = webApp.OpenWebConfiguration(false);
config.ConnectionStrings.ConnectionStrings.Add(new System.Configuration.ConnectionStringSettings("xx", "yy"));
config.Save();