Wrox Programmer Forums
|
ASP.NET 3.5 Basics If you are new to ASP or ASP.NET programming with version 3.5, this is the forum to begin asking questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 20th, 2009, 04:24 AM
Authorized User
 
Join Date: Feb 2009
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by gbianchi View Post
Then you will have a sort of specialized user (it has to at least set up a IIS!), so why not just add a help file to tell the user what to update and where and you forget about all this problems?
I love configurations UI (always do everything you can for the user), but in this case this seems to be rather unnecesary...
Trust me this is not how I want to be doing it either, I'm operating under instructions from the powers that be....a little knowledge is a dangerous thing!
 
Old February 20th, 2009, 04:28 AM
Authorized User
 
Join Date: Feb 2009
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by Imar View Post
Not sure what you're asking it. It seems to work fine but then what?

Imar
It updates the file but then it doesn't redirect to the first page of the website because it doesn't realise that the file has been updated. On load of the website I check the connection string in the web config, if it is empty I go to the setup page otherwise I go to the menu page of the site. When the setup page is shown & the information entered & saved I then redirect to the default page but it checks the web config again & thinks it's still empty so just returns to setup page. If I reload the website manually it works fine but I don't want them to have to do that.

Louisa
 
Old February 21st, 2009, 06:30 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

It depends on where what action takes place.

As soon as you save the web.config, the current application is not restarted directly. Basically what happens is this:

1. A new application domain is started to handle new, incoming requests

2. The old domain is kept alive to *handle the existing connections*

So, the page saving the changes will still be served by the old app domain and its old settings.

My guess is that if you do a client redirect (using Response.Redirect for example), the new request will be handled by the new app domain with the new settings.

If it doesn't, please post the relevant code here.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old February 23rd, 2009, 05:35 AM
Authorized User
 
Join Date: Feb 2009
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Imar,

This is the code on my Default page -
If eXpressWebCommon.General.GetConnectionString = ""Then
'first time in so need to set up the server etc
Response.Redirect("Setup.aspx")
Else
'in case a users profile has been changed we need to clear the settings down and repopulate them
ClearPreviousValues()
GetNewValues()
IfNot IsPostBack Then
If Profile.Message = "1"Then
Response.Redirect("LoginMessage.aspx")
EndIf
EndIf
If InStr(Request.QueryString.ToString, "UPRN") > 0 Then
UPRN = eXpressWebCommon.Web.GetUnencryptedQueryString(Req uest.QueryString.ToString, "UPRN")
eXpressWebCommon.QueryString.SetValue(queryString,
"UPRN", UPRN)
Response.Redirect(
"FrontOfficeDocProduction/RegisterDetails.aspx?ID=" & queryString)
Else
Response.Redirect("FrontOfficeDocProduction/RegisterDetails.aspx")
EndIf
EndIf

And then this is the code on my setup page that updates the web config and redirects back -

ConnectionString = "Server=" & txtServer.Text & ";database=" & txtDBName.Text & ";uid=" & txtUID.Text & ";pwd=" & txtDBPWord.Text
If InStr(txtDocPath.Text, "express") > 0 Then
DocPath = txtDocPath.Text & "\~IMAGES\DocTemplates"
Else
DocPath = txtDocPath.Text & "eXpress\~IMAGES\DocTemplates"
EndIf
With myConfiguration
.ConnectionStrings.ConnectionStrings(
"eXpressDB").ConnectionString = ConnectionString
.AppSettings.Settings.Item(
"Docs").Value = DocPath
.Save()
System.Configuration.ConfigurationManager.RefreshS ection(.ConnectionStrings.SectionInformation.Name)
System.Configuration.ConfigurationManager.RefreshS ection(.AppSettings.SectionInformation.Name)
EndWith
Response.Redirect("Default.aspx")

Thanks for all your help

Louisa
 
Old February 23rd, 2009, 05:44 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Difficult to say something useful because of all the eXpressWebCommon stuff. Where does that come from? Are you sure that part is working fine and retrieves the right information?

Have you tried debugging this to see what code gets hit when?

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old February 23rd, 2009, 05:50 AM
Authorized User
 
Join Date: Feb 2009
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

sorry I didn't think about that!
The common stuff works fine, I've been using it for several years in all my sites, it's just common code to save me reinventing the wheel.

When I run my code in design I get a message box come up saying "This file has been modified outside of the source editor. Do you want to reload it?."

So it is not pulling the changes in & i assume thats whats happening when I publish & run.
 
Old February 23rd, 2009, 05:58 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Quote:
This file has been modified outside of the source editor. Do you want to reload it?."
Not pulling the changes in? This message suggest that the file has been changed while running the application right?

I know this can work as I have done similar stuff in my book ASP.NET 2.0 Instant Results book. Soon as you alter web.config the application should be restarted.

Have you tried this in IIS as well, tather than just in a debugging environment? And as I asked earlier: did you debug? Di you see all code get hit? What happens when you use the API to look into AppSettings or ConnectionStrings shortly after you saved the changes?

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old February 23rd, 2009, 06:05 AM
Authorized User
 
Join Date: Feb 2009
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by Imar View Post
Not pulling the changes in? This message suggest that the file has been changed while running the application right?

I know this can work as I have done similar stuff in my book ASP.NET 2.0 Instant Results book. Soon as you alter web.config the application should be restarted.

Have you tried this in IIS as well, tather than just in a debugging environment? And as I asked earlier: did you debug? Di you see all code get hit? What happens when you use the API to look into AppSettings or ConnectionStrings shortly after you saved the changes?

Imar
When I punblish it and run the site (Live) it just continuously redirects back to the setup page as when it hits the default page each time it thinks there is nothing in the web config. If I shut the IE window and then go back it it redirects correctly, this tells me that the web config has indeed been updated but the site is not aware of these changes. Yes I have debugged and all my code is being hit, it just isn't aware that the web config has been updated.

So the Default page is loaded, it uses the API to see if it has a connection string, it doesn't so it redirects to the setup page which prompts for the info it needs, updates the web config & redirects to the Default page again which once more uses the API to see if it has a connection string, thinks that it doesn't so redirects once more to the setup page and this continues until you close the window. If you look in the web config using notepad or similar at any point during this you can seethat it has been updated just that the new version has not been loaded,
Louisa
 
Old February 23rd, 2009, 06:26 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Something we don't see or that you're not telling us must be going wrong. I can successfully make it work here without a problem. Try this:

1. Create a brand new web site using File | New Web Site

2. Add this to the config:

<appSettings>
<add key="Docs" value="" />
</appSettings>
<connectionStrings>
<add name="eXpressDB" connectionString="" />
</connectionStrings>

3. In the Code Behind of Default add this:

Code:
 
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)  _
            Handles Me.Load
  Dim connectionString As String = _
            WebConfigurationManager.ConnectionStrings("eXpressDB").ConnectionString
  If String.IsNullOrEmpty(connectionString) Then
    Response.Redirect("Setup.aspx")
  End If
End Sub
4. Create Setup.aspx and add this code to its Code Behind:

Code:
 
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) _
        Handles Me.Load
  Dim connectionString As String = "New Connection String"
  Dim myConfiguration As Configuration = _
        WebConfigurationManager.OpenWebConfiguration("~/")
  With myConfiguration
    .ConnectionStrings.ConnectionStrings("eXpressDB").ConnectionString = connectionString
    .AppSettings.Settings.Item("Docs").Value = "Some Value"
    .Save()
  End With
  Response.Redirect("Default.aspx")
End Sub
Works fine for me. As soon as I hit Save() the config gets saved. I then get redirected to Default where the new settings are available.

Try this out, and see if it works for you.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!

Last edited by Imar; February 23rd, 2009 at 06:37 AM..
 
Old February 23rd, 2009, 06:49 AM
Authorized User
 
Join Date: Feb 2009
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

I still got the message about the source file being modified outside of the source editor when running in design.

Louisa





Similar Threads
Thread Thread Starter Forum Replies Last Post
impersonation through web.config and runtime xile ASP.NET 1.0 and 1.1 Professional 0 November 20th, 2008 12:09 PM
web.config vs. app.config darlo Visual Studio 2005 11 August 20th, 2008 07:23 AM
Change datasource of crystal report at runtime check123 Pro VB 6 1 March 21st, 2008 05:45 AM
web.config sonny1 ASP.NET 2.0 Basics 1 October 20th, 2007 01:40 PM
How to change an ASP: Image Url at runtime ergaurav.nex ASP.NET 1.0 and 1.1 Professional 2 September 5th, 2006 03:44 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.