problem reading web.config's <configSection> - returns null

M

Milsnips

Hi all.

i'm tryng to implement the Rewrite.NET url rewritining functionality into a
test project i've created, however i am hitting a problem at this line
(direct from the web example):

System.Collections.Specialized.NameValueCollection SectionIndex =
(System.Collections.Specialized.NameValueCollection)System.Configuration.ConfigurationSettings.GetConfig("Rewrite.NET/Index");

The value always returns me null, and just to check it was reading from the
same web.config, i added a, appSettings value which i could read fine.

These code examples are directly off the web example and nothing is changed,
however the above call to find "GetConfig" section returns null and i dont
know why?? any help appreciated!

Here is what my web.config looks like:

<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="Rewrite.NET">
<section name="SimpleSettings"
type="System.Configuration.NameValueSectionHandler,System" />
</sectionGroup>
</configSections>
<Rewrite.NET>
<SimpleSettings>
<!-- sample test page urls to rewrite -->
<add key="/Default.aspx?page=Home" value="/default.aspx" />
<add key="/Default.aspx?page=About" value="/about.aspx" />
<add key="/Default.aspx?page=Contact" value="/contact.aspx"
/>
</SimpleSettings>
</Rewrite.NET>
<appSettings>
<add key="test" value="test"></add>
</appSettings>
<connectionStrings/>
<system.web>
<httpModules>
<add type="Rewrite.NET.Rewrite,Rewrite.NET"
name="Rewrite.NET" />
</httpModules>
<compilation debug="true" />
<authentication mode="Windows" />
</system.web>
</configuration>

thanks,
Paul
 
G

Guest

Hi all.

i'm tryng to implement the Rewrite.NET url rewritining functionality into a
test project i've created, however i am hitting a problem at this line
(direct from the web example):

System.Collections.Specialized.NameValueCollection SectionIndex =
(System.Collections.Specialized.NameValueCollection)System.Configuration.Co­nfigurationSettings.GetConfig("Rewrite.NET/Index");

The value always returns me null, and just to check it was reading from the
same web.config, i added a, appSettings value which i could read fine.

These code examples are directly off the web example and nothing is changed,
however the above call to find "GetConfig" section returns null and i dont
know why?? any help appreciated!

Here is what my web.config looks like:

<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="Rewrite.NET">
<section name="SimpleSettings"
type="System.Configuration.NameValueSectionHandler,System" />
</sectionGroup>
</configSections>
<Rewrite.NET>
<SimpleSettings>
<!-- sample test page urls to rewrite -->
<add key="/Default.aspx?page=Home" value="/default.aspx" />
<add key="/Default.aspx?page=About" value="/about.aspx" />
<add key="/Default.aspx?page=Contact" value="/contact.aspx"
/>
</SimpleSettings>
</Rewrite.NET>
<appSettings>
<add key="test" value="test"></add>
</appSettings>
<connectionStrings/>
<system.web>
<httpModules>
<add type="Rewrite.NET.Rewrite,Rewrite.NET"
name="Rewrite.NET" />
</httpModules>
<compilation debug="true" />
<authentication mode="Windows" />
</system.web>
</configuration>

thanks,
Paul

I'm not sure, but what does "Index" mean in "Rewrite.NET/Index"?
 
M

Milsnips

Aah yes, that was the problem, there was a missing line in web.config with
name "Index" within the group section.
thanks,
Paul

Hi all.

i'm tryng to implement the Rewrite.NET url rewritining functionality into
a
test project i've created, however i am hitting a problem at this line
(direct from the web example):

System.Collections.Specialized.NameValueCollection SectionIndex =
(System.Collections.Specialized.NameValueCollection)System.Configuration.Co­nfigurationSettings.GetConfig("Rewrite.NET/Index");

The value always returns me null, and just to check it was reading from
the
same web.config, i added a, appSettings value which i could read fine.

These code examples are directly off the web example and nothing is
changed,
however the above call to find "GetConfig" section returns null and i dont
know why?? any help appreciated!

Here is what my web.config looks like:

<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="Rewrite.NET">
<section name="SimpleSettings"
type="System.Configuration.NameValueSectionHandler,System" />
</sectionGroup>
</configSections>
<Rewrite.NET>
<SimpleSettings>
<!-- sample test page urls to rewrite -->
<add key="/Default.aspx?page=Home" value="/default.aspx" />
<add key="/Default.aspx?page=About" value="/about.aspx" />
<add key="/Default.aspx?page=Contact"
value="/contact.aspx"
/>
</SimpleSettings>
</Rewrite.NET>
<appSettings>
<add key="test" value="test"></add>
</appSettings>
<connectionStrings/>
<system.web>
<httpModules>
<add type="Rewrite.NET.Rewrite,Rewrite.NET"
name="Rewrite.NET" />
</httpModules>
<compilation debug="true" />
<authentication mode="Windows" />
</system.web>
</configuration>

thanks,
Paul

I'm not sure, but what does "Index" mean in "Rewrite.NET/Index"?
 
M

Milsnips

Just one more question regarding url rewriting -

In my code example i put a rule, say "Default.aspx?id=4" - rewrite to
"products/default.aspx", and as i step through the code i can see it does
everything correctly, but when it gets to displaying the page, it says
"products/default.aspx not found"!

I assumed this just rewrote the name virtually that appears on the page
links/ or address bar, but not actually physically redirect to the location?

Have i misunderstood something here?
thanks,
Paul
 
G

Guest

Just one more question regarding url rewriting -

In my code example i put a rule, say "Default.aspx?id=4" - rewrite to
"products/default.aspx", and as i step through the code i can see it does
everything correctly, but when it gets to displaying the page, it says
"products/default.aspx not found"!

I assumed this just rewrote the name virtually that appears on the page
links/ or address bar, but not actually physically redirect to the location?

Have i misunderstood something here?
thanks,
Paul













- Show quoted text -

It looks like you forgot to add a configuration line for

products/default.aspx

into web.config.

I think you should check the manual for software you used (I don't
know what Rewrite.NET is)
 
M

Milsnips

Rewrite.NET is some free code on the web to handle url rewriting in
asp.net - link: http://www.15seconds.com/issue/030522.htm

Anyway, to test my example i added the line in web.config:
<add key="/Default.aspx?id=4" value="/products/default.aspx" />

So, when i run it, i type in "localhost/project/default.aspx?id=4" and it
goes through the rules and finds it and calls the function:
Appl.Context.RewritePath("/products/default.aspx"); and here i get the 404
error saying page not found.

I thought that it was just meant to virtually rename the page url, but in
the background still use "default.aspx?id=4" ??

regards,

Paul



Just one more question regarding url rewriting -

In my code example i put a rule, say "Default.aspx?id=4" - rewrite to
"products/default.aspx", and as i step through the code i can see it does
everything correctly, but when it gets to displaying the page, it says
"products/default.aspx not found"!

I assumed this just rewrote the name virtually that appears on the page
links/ or address bar, but not actually physically redirect to the
location?

Have i misunderstood something here?
thanks,
Paul













- Show quoted text -

It looks like you forgot to add a configuration line for

products/default.aspx

into web.config.

I think you should check the manual for software you used (I don't
know what Rewrite.NET is)
 
G

Guest

Rewrite.NET is some free code on the web to handle url rewriting in
asp.net - link:http://www.15seconds.com/issue/030522.htm

Anyway, to test my example i added the line in web.config:
<add key="/Default.aspx?id=4" value="/products/default.aspx" />

So, when i run it, i type in "localhost/project/default.aspx?id=4" and it
goes through the rules and finds it and calls the function:
Appl.Context.RewritePath("/products/default.aspx"); and here i get the 404
error saying page not found.

I thought that it was just meant to virtually rename the page url, but in
the background still use "default.aspx?id=4" ??

regards,

Paul









It looks like you forgot to add a configuration line for

products/default.aspx

into web.config.

I think you should check the manual for software you used (I don't
know what Rewrite.NET is)- Hide quoted text -

- Show quoted text -

Paul, what the URL you want to rewrite?

As I understood, you have a page named default.aspx, located in /
project

So, the URL

http://localhost/project/default.aspx?id=4

should work somehow without any rewriting engine.

The Rewrite.NET is designed to make

http://localhost/products/default.aspx or http://localhost/project/products/default.aspx

working as

http://localhost/project/default.aspx?id=4

So, you should call http://localhost/products/default.aspx or
http://localhost/project/products/default.aspx to get it working.

As second, you page is under "/project" and the config key refer to
"/"

<add key="/Default.aspx?id=4" value="/products/default.aspx" />
 
M

Milsnips

Hi Alexey,

Thanks for the info, yes i understand what you mean however this is what i
am trying to achieve..
"
say i have a online store with dynamic product list, instead of my page
showing http://onlinestore/shop/product.aspx?id=25, I want to show:
http://onlinestore/shop/25/nokia-6610.htm

I've seen it on many sites and im pretty sure that nokia-6610 is a
non-existant file, just a virtual redirection from products.aspx?id=25 - if
you know what i'm after.

thanks,
Paul


Rewrite.NET is some free code on the web to handle url rewriting in
asp.net - link:http://www.15seconds.com/issue/030522.htm

Anyway, to test my example i added the line in web.config:
<add key="/Default.aspx?id=4" value="/products/default.aspx" />

So, when i run it, i type in "localhost/project/default.aspx?id=4" and it
goes through the rules and finds it and calls the function:
Appl.Context.RewritePath("/products/default.aspx"); and here i get the
404
error saying page not found.

I thought that it was just meant to virtually rename the page url, but in
the background still use "default.aspx?id=4" ??

regards,

Paul









It looks like you forgot to add a configuration line for

products/default.aspx

into web.config.

I think you should check the manual for software you used (I don't
know what Rewrite.NET is)- Hide quoted text -

- Show quoted text -

Paul, what the URL you want to rewrite?

As I understood, you have a page named default.aspx, located in /
project

So, the URL

http://localhost/project/default.aspx?id=4

should work somehow without any rewriting engine.

The Rewrite.NET is designed to make

http://localhost/products/default.aspx or
http://localhost/project/products/default.aspx

working as

http://localhost/project/default.aspx?id=4

So, you should call http://localhost/products/default.aspx or
http://localhost/project/products/default.aspx to get it working.

As second, you page is under "/project" and the config key refer to
"/"

<add key="/Default.aspx?id=4" value="/products/default.aspx" />
 
G

Guest

Hi Alexey,

Thanks for the info, yes i understand what you mean however this is what i
am trying to achieve..


Sorry, but...

you have the following in the config

<add key="/Default.aspx?id=4" value="/products/default.aspx" />

It means you should call /products/default.aspx to rewrite from /
Default.aspx?id=4

Please check the original example at http://www.15seconds.com/issue/030522.htm
 
M

Milsnips

Hi Alexey,

yes you are right! i misunderstood it and was doing the key/value the wrong
way around that is why i was getting the problem.
I understand it now well. thanks again for your time and help.

regards,
Paul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,072
Latest member
trafficcone

Latest Threads

Top