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


Similar Messages:

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

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

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

Is Default Value Necessary For The Validation To Fire Properly On Custom Config Section's Properties

Jul 26, 2010

i have the following property which takes an IP address as its value and defined in my custom config section as follows and To validate the IP address i am using a Reg expression.

[ConfigurationProperty("SMTPServer", IsRequired = true, DefaultValue = "0.0.0.0")

View 1 Replies

Use WebConfigurationManager To Get Section From Specific Config File?

May 14, 2010

I am trying to get sections from specific .config file such like "my.config".
WebConfigurationManager.OpenWebConfiguration can get the web.config in specific path.
Maybe WebConfigurationManager.OpenMappedWebConfiguration can reach my purpose

View 2 Replies

Web Forms :: Programmatically Adding The WCF Section In Web.config File?

Jan 20, 2010

i want Programmatically add the WCF section <system.serviceModel> to web.config file using C# and .aspx control.

View 1 Replies

IIS Configuration :: Adding Add Section In HttpHandler Section In Web Config Results In Blank Page?

Jul 12, 2013

with this code website works perfect

<configuration>
<system.web>
<httpHandlers>
</httpHandlers>
</system.web>
</configuration>

but when I add

<add path="ThumbHandler.ashx" verb="*" type="Delshad.WebControls.ThumbHandler,Delshad.ThumbPic"/>

or

<add verb="GET" path="CaptchaImage.axd"
type="MSCaptcha.CaptchaImageHandler, MSCaptcha" />

in httphandlers section when I go in my site it is only a blank page!

before In other two host there wasent problem but this is a new host and I face with this problem.also in local there isn't any problem.

View 1 Replies

Custom Server Controls :: Unable To Create A Forgot Password Section Within Login Section

Mar 10, 2011

I am trying to create a forgot password section within my login section and it doesnt seem to work.

In my forgotpassword.aspx page my code looks like this:

[code]....

According to our records, you have requested that your password be reset. Your new password is: <%Password%>

If you have any questions or trouble logging on contact a site administrator.

No connection could be made because the target machine actively refused it ::1:25

Description: An unhandled exception occurred during the execution of the current web request. review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it ::1:25

View 2 Replies

Custom Server Controls :: Implementing An Interface From A Class Library In A Custom Control?

Jul 8, 2010

I'm building an n-tier application, with the web client and the class library separate. I'm also using the factory pattern of development, using interfaces to act as containers for different objects they are associated with. The problem I'm expreriencing is that I declared a public interface class in the class library and I can create an instance of it in in my aspx pages but whenever I declare it in my custom control code-side, i get an error, like so:

Error 20 The type or namespace name 'IContentMaker' could not be found (are you missing a using directive or an assembly reference?)

notge that I have inherited the class library namespace using the 'using' keyword just in case you are wondering. My code is like so:

using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using TQO_Classes ; //importing the class library project
public partial class PageContentMgr : System.Web.UI.UserControl
{
private IContentMaker _data; //this line throws the error, it works fine on aspx pages

View 1 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

Configuration :: Create A Custom Error Page In Web.config File?

Apr 14, 2010

If I create a custom error page in my web.config file, how do I retrieve error details in the error page?

So with ...

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

I am referring to errors generated by my asp.net. For example I created a sample page and wrote 'throw new Exception("some error")' as a test. How can I retrieve an instance of the exception or exception details in my "/error/error.aspx" page? Currently in my error page if I query Server.GetLastError() the return value is null.

View 6 Replies

Why Can't Add Section To Machine.config

Mar 31, 2011

I would like to add this section to my machine.config in exactly the same way many articles and microsoft are suggesting:

<configuration>
<system.net>
<connectionManagement>
<add name = [URL]/>
<add name = "*" maxconnection = "2" />
</connectionManagement>
</system.net>
</configuration>

[URL] As soon as I do it though, I get this exception when trying to hit a page hosted on the IIS on the same machine: Parser Error Message: Unrecognized configuration section system.net. Source Error:

Line 9: settings that differ from their defaults.
Line 10: --><configuration>
Line 11: <system.net>
Line 12: <connectionManagement>
Line 13: <add address="*" maxconnection="24" />

Source File: C:WINDOWSMicrosoft.NETFramework64v2.0.50727Configmachine.config Line: 11 Where is the problem and how can I modify the machine.config so that I can finally control the maxconnection value?

View 3 Replies

Security :: Encrypting Section In Web.config?

May 3, 2010

I am wondering how to encrypt the below information in the "web.config" file of the "Account" folder (where we have the secured pages):

[Code]....

My issue here is that even after I compiled my application (using "aspnet_compiler -v /reports c:
eports"), the information inside the web.config file of the Account folder still not encrypted, and I want to publish my site to the customer server. So, since this server is a customer server, then they can access this "web.config" file and change our web-application security behaviour (correct me if I am wrong). Basically, I don't want the customer to even have access to our secured pages when they access our web-application using the web browser. How to solve this issue?

View 2 Replies

C# - Best Way To Get The Proper Modules Section From The Web.config?

Jan 19, 2011

The code I've used to get the HTTP Modules is basically

HttpModulesSection modules = ((SystemWebSectionGroup)config.GetSectionGroup("system.web")).HttpModules;
// Depending on what we need to do...
//modules.Modules.Add(CreateSomeModule());
//modules.Modules.Remove("SomeOtherModule");

This worked fine up until IIS7. The migration command %SystemRoot%system32inetsrvappcmd migrate config "website/" moves the modules into system.webServer, so my code is now updating the wrong section. Is there a built in way to get the proper module section that should be modified? Or do I have to add a check for the Request.ServerVariables["SERVER_SOFTWARE"] and return system.web/system.webServer depending on the string I get back?

View 1 Replies

MVC :: How To Respect Namespaces Section In Web.config

Nov 18, 2010

I am referencing some classes in my _layout.cshtml file and I have the namespaces in my Views/web.config <pages><namespaces> section and the layout page does not resolve. If I put @using statements in the layout page, it works fine. Shouldn't the layout page respect the web.config section?

View 5 Replies

Error Trying To Read Roles Section From Web.Config

Feb 21, 2010

When executing this line:

Dim roleRedirectSection As LoginRedirectByRoleSection = DirectCast(ConfigurationManager.GetSection("loginRedirectByRole"), LoginRedirectByRoleSection)

...I get the following error:

Message: "An error occurred creating the configuration section handler for loginRedirectByRole: Could not load type 'sitename.LoginRedirectByRoleSection'. (W:Webs2010DEVsitenameASP 4.0web.config line 10)"

<configuration>
<configSections>
<section name="loginRedirectByRole" type="journeyeast.LoginRedirectByRoleSection" allowLocation="true" allowDefinition="Everywhere" />
</configSections>
<loginRedirectByRole>
<roleRedirects>
<add role="Administrator" url="~/Account/Admin/Default.aspx" />
<add role="Employee" url="~/Account/Emp/Default.aspx" />
<add role="Teacher" url="~/Account/Teacher/Default.aspx" />
<add role="Student" url="~/Account/Student/Default.aspx" />
<add role="School" url="~/Account/School/Default.aspx" />
</roleRedirects>

View 1 Replies

MachineKey Config Section Default Location?

Sep 21, 2010

Where do I find the machineKey config section for ASP.NET?

I don't have one in my application Web.config, there isn't one in the root Web.config and there isn't one in my machine.config.

Does this mean there is some other default hardcoded into ASP.NET? If so, what are the defaults? (For .NET 2 and 4)

Having read this: [URL]

i was expecting to find something like this, somewhere:

<machineKey
validationKey="AutoGenerate,IsolateApps"
decryptionKey="AutoGenerate,IsolateApps"
/>

Edit: the 1.1 docs seem fairly clear wrt default values: [URL] but the 4 docs are rather ambiguous [URL]

View 1 Replies

Access HttpRuntime Section Of Web.config From Codebehind?

Feb 3, 2011

actually i need the maxRequestLength value of the httpRuntime section in web.config to check if a postedfile's size is greater. What's the best way to read it?

View 1 Replies

Custom Server Controls :: Implementing PostBackUrl Feature In A Custom Server Control?

Dec 20, 2010

I've build a custom server control inheriting from WebControl. Basically it is a kind of button. All is working perfectly except one thing: the PostBackUrl is inoperative.

I probably forgot to implement something. Actually I just added the property PostBackUrl. Probably I should also implement an interface of call something.

View 4 Replies

Security :: Authorization Section - Web.config Denying All Users

Jan 1, 2011

In my web.config file, I have an authorization section that is supposed to deny all users EXCEPT for those included in the group specified. However, my login form doesn't allow these users to proceed to the next page - the login form just reappears as if the user has been denied. Code:

[Code]....

I have a user named 'test' that is in the Student Council group. I've tried 'allow users' and 'allow roles' with no success. I've also confirmed that the user is able to log into any workstation in my domain.

View 20 Replies

Implementing Custom MappingSource?

Mar 18, 2010

I am looking at implementing a custom MappingSource as side project. It needs to be something along the lines of AttributeMappingSource and XmlMappingSource, except that it won't be using attributes or xml. This has been a problem so far. All the documentation I've seen uses these two, and only these two. I know how to define the new classes and implement the abstract methods, but there are a few problem. Let's take a look at the mapping source first:

public class CustomMappingSource : MappingSource
{
protected override MetaModel CreateModel(Type dataContextType)
{
// it is suggested to create a new metamodel and pass in
// the current metamodel held in the datacontext.
return new CustomMetaModel(GetModel(dataContextType));
}
}

Ok so far, except that it's a new generic context, and no model exists yet. For example, I want to be able to do this:

DataContext = new DataContext(connectionString, new CustomMappingSource());

Now let's look at one of the CustomMetaModel's overriden methods:

public override MetaTable GetTable(Type rowType)
{
// there are no methods or collection exposed in 'this' to
// add, remove or alter the table mappings.
}

How do I do this? as you might be guessing at this point, I am looking into building a FluentMappingSource. NO! Don't point me to FluentLinqToSql. I have it and their mapping source isn't even derived from MappingSource.

View 1 Replies

Add A Namespace Element To The System.web Pages Namespaces Section Of The Web.config?

Mar 26, 2011

If I add a namespace element to the system.web pages namespaces section of the web.config do I still have to add references in the code behinds in order to have access to the members of that namespace at design-time?

View 1 Replies

Asp.net - Working With Generic Lifetime Managers In Unity Config Section

Apr 28, 2010

I have the following generic lifetime manager

[code]...
causes the following error
Cannot create an instance of UI.Common.Unity.RequestLifetimeManager`1[T] because Type.ContainsGenericParameters is true.How do you reference generic lifetime managers?

View 1 Replies







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