Add Custom Locations At Runtime Without Modifying Web.config?

Nov 17, 2010

I have an xml file with custom routes that I'm creating routes from on Application_Start in Global.asax. Some of those routes require authentication, some don't. Currently I have "location" entries for all those routes in web.config to control authorization.

I wonder whether there is a way to configure locations on application start at the same time I configure routes, so that I don't need to have entries in web.config.

View 1 Replies


Similar Messages:

Modifying Root Web.config In Code?

Jan 30, 2011

I would like to store some meta-information about a given site instance that can (a) be managed by that site instance and (b) persist clobbering of Web.config file.The site will run in multiple environments (dev,testing,staging and production) and each environment can have different values for this metadata.
Note: All environments are running IIS 7.0+

The Root Web.config seems very appealing, as it is certainly outside of the website. Therefore, both files and databases can be changed while maintaining the metadata. I have seen how to modify the appSettings of the Web.config stored in the website, but is it possible to similarly modify the appSettings in the Root Web.config (Specifically within the proper directive)?

View 2 Replies

Modifying Web.Config Handlers Section Generates Extra Unneeded Entries?

Jul 19, 2010

I've written a command line tool that deploys HTTP Handlers to an applications Web.Config file using a combination of System.Configuration, System.Web.Configuration and Microsoft.Web.Administration since it needs to register the handlers for both Classic and Integrated Modes as I don't know what mode end users will be using for their IIS deployments.

My issue is that is that when the tool is run the <handlers> section under <system.webServer> gets filled with the following extra unecessary entries as well as the entries I wanted to add:

[code]...

why this might be happening and how I can stop it?

When I save my configuration opened with System.Web.WebConfigurationManager I use ConfigurationSaveMode.Minimal so any inherited configuration (which is what this appears to be) should not get written.

View 1 Replies

Security :: Creating Web.config At Runtime

Jan 23, 2010

1. On OnCreatedUser event, I create a folder for each members, so that they can store their files inside those. The thing is I use User.Provider key as a folder name. Is this a good way to store? Is this OK from security view point. Otherwise I am planning to use the User.Username. Here are the codes inside the OnCreatedUser event.

[Code]....

2. Inside these user folders I want to put web.config at run time [at the time of registration]. So that a member cannot access files of other members at any cost. Do you have any idea on creating web.config file at runtime inside these folders? Else if you can provide me any other options, I am eager to listen that. I don't want to call database frequently. So if there is any easy solution.

View 3 Replies

Rewrite Web.config Connection String At Runtime?

Mar 4, 2010

How to rewrite Webconfig connection string at runtime.I want Read from textbox and write into webconfig.

View 1 Replies

DataSource Controls :: Set Up Connectionstring At Runtime From Web.config - MySQL?

Jul 7, 2010

I want to setup the connectionstring of the SqlDatasource of a dropdown list at runtime, eg. Page Load event. I have install MySQl ODBC driver, System DSN name as "MySQL_Employee" If I have an entry in Web.config:

<connectionStrings>
<add name="mysqlConnection" connectionString="DSN=MySQL_Employee;UID=john;description=connection to employee database;server=empServer;database=employee;port=3306;" providerName="System.Data.Odbc"/>
</connectionStrings>

View 1 Replies

C# - Programmatically Edit External Config Files At Runtime?

Mar 1, 2011

By external config files, I mean .config files other than web.config. I've seen all the examples on how to edit web.config at runtime, but I want to edit a config file referenced by a configSource for appSettings. I want to modify only the external file and I will handle the app recycle.

I would like to use a built-in class to deal with the edits, but if the only option is a manual File open/parse, etc, then sobeit.

The general behind all this being a Settings page that is viewed at app startup, user sets their particulars and then saves the changes, then the real app starts up. quick and easy install app/configure page, so I'd like to leverage .config if at all possible.

FOLLOWUP - Quick Snippet to use XmlDocument to change an appSetting key value:

string path = Server.MapPath("~/my.config");
XmlDocument doc = new XmlDocument();
doc.Load(path);
XmlNode node = doc.SelectSingleNode("/appSettings/add[@key='myKey']");
node.Attributes[1].Value = "myVal";
XmlTextWriter writer = new XmlTextWriter(path, null);
writer.Formatting = Formatting.Indented;
doc.WriteTo(writer);
writer.Flush();
writer.Close();

View 2 Replies

Web Forms :: Updating Database Name In Connection String In Web Config At Runtime

Feb 21, 2012

My problem is i need to update only the database name in current connection string in web.config at runtime....

this is the sample code .. to update connection string . but it updates the name of connection string  i need to change the database name of connection string !

public static void UpdateConnection(string name, string connString) {
var webConfig = new ExeConfigurationFileMap {
ExeConfigFilename = GlobalSettings.FullpathToRoot + "web.config" };

[Code] ....

View 1 Replies

Security :: Prevent A Runtime Loaded Assembly From Accessing The Web.config File?

Jul 19, 2010

I have an asp.net 4.0 site. I have CAS turned on for legacy support. But in CAS, is there a way to prevent a runtime loaded assembly from accessing the web.config file? I don't see a permission set that denies access to configuration information.

View 1 Replies

MVC :: Runtime Sitemap Construction For Each Index() ActionMethod - Custom Attribute?

Jun 21, 2010

Recently, I wrote code that dynamically builds a menu / navbar for my site that uses Reflection upon the [Authorize(Roles="")] attribute to determine what Controllers and ActionMethods should be shown to the user. And it came out really well. See this post for the details on how I did it: [URL]

The next step that I've been thinking about is when the user clicks on the "Controller" listing, it takes the user to the Index page. (eg. [URL] ) Which is perfectly fine, but I was thinking that it would be nice to also have this Index page for each controller dynamically constructed based on the user's roles / permissions. For example, if the Index page from XYZ-Controller might look like:


XYZ-Controller Index
SomeMethod1 -- This method tweaks your widgets
SomeMethod2 -- This method unwinds your widgets, re-orders thems, and then re-winds them, but only on Tuesdays.
SomeMethod3 -- This method will delete some or all of your widgets and then you'll be sad.

I currently use Reflection to iterate thru all my Controllers and all the ActionMethods in each controller. I've been pondering the best way to store the Description of each ActionMethod. (Like, "This method tweaks your widgets.") Do I make my own Attribute called, say, Description which I would use to decorate ActionMethods with. For example it might look like this: [Description("This method tweaks your widgets")]

View 2 Replies

Custom Server Controls :: TypeConverter Generates Parser Error At Runtime?

Jun 20, 2010

I'm building a custom control that has a ValidationText property of type List<string>. The value of the property is rendered as a comma-delimited string in the XHTML code. Changing the value in the String Collection editor updates the XHTML code and vice versa. So everything seems to work at design time. But... when I run the project I get a parser error:

"Cannot create an object of type 'System.Collections.Generic.List`1[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]' from its string representation 'hh,ss' for the 'ValidationText' property."

Here is the code for the property:

[Code]....

...and the Typeconverter:

[Code]....

View 2 Replies

C# - How To Create And Use A Custom Section In Web.config

Jul 10, 2010

how to create and use a custom section in web.config ?

View 3 Replies

C# - App.Config Custom Configuration Section

Dec 14, 2010

I've created a custom config section for my application. For some reason Visual Studio 2010 isn't picking up and of my custom properties. I'm getting warnings similar to this for all the "add" keys: Could not find schema information for the element 'urlFilterSection'

CONFIG FILE:
<configSections>
<section name="urlFilterSection" type="BotFinderApp.Models.UrlFilterSection, BotFinder" />
</configSections>
<urlFilterSection>
<urlFilterCollection>
<add url="urlhere.com.au" numberOfIpsToExtract="10" />
<add url="urlhere.com.au" numberOfIpsToExtract="10" />
<add url="urlhere.com.au" numberOfIpsToExtract="10" />
<add url="urlhere.com.au" numberOfIpsToExtract="10" />
<add url="urlhere.com.au" numberOfIpsToExtract="10" />
<add url="urlhere.com.au" numberOfIpsToExtract="10" />
<add url="urlhere.com.au" numberOfIpsToExtract="10" />
<add url="urlhere.com.au" numberOfIpsToExtract="10" />
<add url="urlhere.com.au" numberOfIpsToExtract="10" />
</urlFilterCollection>
</urlFilterSection>
UrlFilterSection:
namespace BotFinderApp.Models
{
public class UrlFilterSection : ConfigurationSection
{
public UrlFilterSection()
{
}
[ConfigurationProperty("urlFilterCollection", IsDefaultCollection = false)]
[ConfigurationCollection(typeof(UrlFilterCollection), AddItemName = "add", ClearItemsName = "clear", RemoveItemName = "remove")]
public UrlFilterCollection Urls
{
get
{
var urlsCollection = (UrlFilterCollection)base["urlFilterCollection"];
return urlsCollection;
}
}
}
}
UrlFilterCollection
namespace BotFinderApp.Models
{
public class UrlFilterCollection : ConfigurationElementCollection
{
public UrlFilterCollection()
{
}
protected override ConfigurationElement CreateNewElement()
{
return new UrlFilter();
}
protected override object GetElementKey(ConfigurationElement element)
{
return ((UrlFilter)element).Url;
}
}
}
UrlFilter
namespace BotFinderApp.Models
{
public class UrlFilter : ConfigurationElement
{
public UrlFilter()
{
}
[ConfigurationProperty("url", DefaultValue = "", IsRequired = true)]
public string Url
{
get { return (string)this["url"]; }
set { this["url"] = value; }
}
[ConfigurationProperty("numberOfIpsToExtract", DefaultValue = "0", IsRequired = true)]
public int NumberOfIpsToExtract
{
get { return (int)this["numberOfIpsToExtract"]; }
set { this["numberOfIpsToExtract"] = value; }
}
}
}

View 2 Replies

Reading Custom Config Sections From C#?

Feb 17, 2011

The below is the custom config files

<Test>
<testA att1="A" att2="B" att3="C"/>
<testB att1="A" att2="B" att3="C"/>
</Test>

If I send testA then the class will return all testA attributes i.e att1, att2 and att3 values.

testA, testB will vary.. that means in future we will add another two tags i.e testC, testD and so on.

My application will be returned all the attributes based on my inout (testA...).

View 2 Replies

Encrypting Custom Sections Of A Web.config?

Aug 17, 2010

I used the article Creating a Flexible Configuration Section Handler to create a Flexible Configuration Section Handler in my application.

I also saw this article entitled Encrypting Custom Configuration Sections on the OdeToCode blog, on how to encrypt portions of a web.config file.

From the first article, we have this web.config code.

[code]...

View 2 Replies

Configuration :: Custom Config Files Encryption

Mar 24, 2011

I have a couple of configuration files flxConnection.config and flxSecurity.config files which are being referenced from the Machine.config file like below.

<securitySettings configSource="flxSecurity.config" />
<connectionStrings configSource="flxConnection.config" />

I would like to encrypt the files (a) flxSecurity.config and (b) flxConnection.config using the RSAProtectedConfigurationProvider using a custom RSA key, which can be deployed to other servers. How is that possible? If possible, looked at a variety of stuff in the internet and they all seem to be referring to either Web.config or Machine.config encryption which is pretty straight-forward. This is how the flxConnection.config looks like,

<?xml version="1.0"?>
<connectionStrings>
<add name="LocalSqlServer" connectionString="data source=.SQLEXPRESS;Integrated
Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
</connectionStrings>

This is how the flxSecurity.config looks like,

<?xml version="1.0" encoding="UTF-8"?>
<securitySettings>
<add key="APC_APP_ID" value="apcrpt"/>
</securitySettings>

View 3 Replies

Configuration :: Registering A Custom Section In Web.config?

Feb 12, 2010

I'm getting an ConfigurationErrorsException when trying to load a custom section from my web.config.

I'm trying to register a custom section in web.config to load it later using a "Section Class".
Suppose my section is orderService, and I register it in web.config as shown:
<configuration>
<configSections>
<sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
</sectionGroup>
<section name="orderService" type="orderService"/>
</configSections>
<orderService available="true" pollTimeout="00:01:00" location="abc">
</orderService>
<appSettings></appSettings>
<connectionStrings/>

Then I try to load it with:

Configuration config = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
OrderService custSection = OrderService)config.GetSection("orderService"); <== The exception is thrown here (OrderService is a class that inherits from the class ConfigurationSection, and that defines a property for each orderService property, in this case: available, pollTimeout and location)

The exception says: An error occurred creating the configuration section handler for orderService: Could not load type 'orderService'. (my web.config path line 23) Does anybody know what am I doing wrong here? (I got it from the book APress: Pro ASP.NET 3.5 in C#)

View 2 Replies

C# - Implementing A Custom Section In The Web.config File?

Jun 19, 2010

I've been working on implementing a custom section in the web.config file for a little something I'm working for the past few hours, but I can't seem to get it working. The following is what I'd like to use as my XML structure:

[code]....

View 1 Replies

Security :: Adding Custom Membership To Web.config?

Nov 30, 2010

I'm currently writing a website in VWD2010 Express, which requires me to write a custom membership provider.

I've followed the tutorial here [URL] , which seems relatively straight forward.

I am, however, struggling at the stage where the custom membership provider is included in a site. Now obviously the tutorial writer is using a different version of VS to me, so I've had to adapt it somewhat. Instead of building the class as a dll, and referencing that in a new site, I've started a new site from scratch and added the custom membership provider to the Add_Code file (HDIMembershipProvider.vb). It is now required that I add details of the provider to the web.config file, which seems to be where I am encountering problems.

The tutorial requires me to add:

[Code]....

within the System.Web part of the web.config file. However, upon running the site I get the error:

Could not load type 'HDI.AspNet.Membership.HDIMembershipProvider'.

I realise that how you reference the class must have changed since the tutorial was written, but I can't for the life of me find the format I should be using, and trial&error has turned up nothing so far.

View 2 Replies

MVC :: Custom Template For Web.config In View Folder?

Dec 6, 2010

I've created a class which extends System.Web.Mvc.ViewPage which I want to be the default class each view inherits from. This is controlled by the "pageBaseType" attribute in the "pages" element in the web.config file in each Views folder. If I add a Views folder in Visual Studio, it creates the web.config.

I would like to change the template it uses to do this to use a different value for pagBaseType. I assume there is a template somewhere I could modify, but I don't know where it is.

View 4 Replies

How To Register Custom Control In Web.config File

Dec 25, 2010

I have one custom control. I add reference to it on ASPX pages like this:

<%@ Register TagPrefix="cus" Namespace="Controls" %>

at run time there is no error.

Error shown at deploy time

Unknown server tag 'cus:GridHeaderFilter'.

My custom control is in App_Code folder with name GridHeaderFilter.vb

So how to add or register this custom control in web.config file

View 1 Replies

Put Custom AppSettings Web.config Data Into The ApplicationState?

Mar 7, 2011

I've got some custom values in the AppSettings, in my web.config file.

These values get checked upon every Request.

eg.

So if every request checks the web.config file for the value of this key, would be be smart to put this into the Application cache (eg. via the global.asax) instead of checking this value EVERY request?

I'm assuming that when we read a value from the AppSettings, the website does a physical read of the web.config file? or is this information also all read into Memory when the website starts up and all references to any appSettings information is just an inmemory read .. not a disk I/O read?

View 2 Replies

Configuration :: Read Custom Tags In Web.config In C#?

Sep 1, 2010

<rahul>
<test">
<FileExtensions>

[code]...

View 3 Replies

How To Custom Web.config In Visual Studio Setup Project

Mar 24, 2010

In the Setup Project I have 2 web.config files: web.config - used during the development and web_dist.config - the one that should be included into Setup Project. I must be sure the the Setup project will NOT include the web.config and will always include web_dist.config.

In the File System -> Web Application Folder I have added the Content Files from the project.
Also included the web_dist.config and mapped it to the web.config.

But this gives the warning:

WARNING: Two or more objects have the same target location ('[targetdir]web.config') And the actual config file included is web.config and not web_dist.config. What would be the best option to include the web_dist.config (and named as web.config in the setup)?

View 2 Replies

Web Config - Implementing A Custom Error Page On An .Net Website?

Jan 29, 2010

I have an ASP.Net website and I want to use a custom error page. I put the following code in my web.config

<customErrors mode="On" defaultRedirect="~/error.aspx">
<error statusCode="404" redirect="~/error.aspx" />
</customErrors>

The problem is when i go to a URL that does not exist is still uses the 404 error page specified in IIS Manager.Question: How can I make it use the error.aspx page I have created? Why do the settings in IIS Manager override the web.config?

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved