Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 4 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB 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 April 17th, 2012, 02:39 PM
Authorized User
 
Join Date: Sep 2011
Posts: 41
Thanks: 3
Thanked 4 Times in 3 Posts
Default Roles bombing in production

Hi,

I set up everything in development. The roles works fine. Then I used a script to copy/recreate the dev database to my godaddy.com server (shared hosting). I copied all my web files to godaddy, (with a reconfigured web.config).

But now, it bombs in production (prod). When <roleManager enabled = "true"> in my web.config, I get the following error msg. However, if this is set to "false", it is able to connect to the prod DB. But of course, my roleManager is then not working.

"A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified) "

***

In WSAT, I click the PROVIDER link and then click "Select a different provider for each service (advanced)" link. There are two providers listed:

Membership Provider. The test link connects to the DB.

Role Provider. There are 2 items here. The AspNetSqlroleProvider has the radio button selected. The test link for this item fails. The following error message appears:

"Could not establish a connection to the database.
If you have not yet created the SQL Server database, exit the Web Site Administration tool, use the aspnet_regsql command-line utility to create and configure the database, and then return to this tool to set the provider."

***

In my web.config, I only have a Membership provider:

Code:
  <roleManager enabled="true" />
      <membership>
          <providers>
              <clear />
              <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="apt" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" applicationName="/" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" passwordStrengthRegularExpression=""/>
          </providers>
      </membership>
Do I need to have a provider for Roles? I don't have a deep understanding in this area so I've been just trying to follow the book lead/example. Hence, I am really at a loss on how to diagnose this further. I've spent at least a 1/2 day stuck ... of course, I've tried searching the Internet forums for answers but to no avail ... help is appreciated ... thanks!
 
Old April 17th, 2012, 03:05 PM
Authorized User
 
Join Date: Sep 2011
Posts: 41
Thanks: 3
Thanked 4 Times in 3 Posts
Default P.S. ...

p.s.,

as a workaround, I tried to programmatically check Roles. the book says that by using:

if (User.IsInRole("Managers"))
{
}

I do not have to have Role Manager enabled to use this feature.

However, when I try to use this code in my master code behind file, it doesn't detect "User" ... when I try this code in a regular aspx code behind file, it detects it ...

This feature is useful if I can place it in a master file code behind. Why does it not find "User"? The closest item is "UserControl".

???
 
Old April 18th, 2012, 02:06 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Take a look at this:

Quote:
connectionStringName="apt"
For membership, you changed the connection string to the one you configured for your application. You need to change the settings for the roleManager as well so it also points to the apt connection string. Appendix B, page 774 shows an example and page 773 and further explain why you need this.

Quote:
the book says that by using:

if (User.IsInRole("Managers"))
{
}

I do not have to have Role Manager enabled to use this feature.
I don't think that's what I said in the book. Where did you find this? (Would neexd to correct it if I did say it like that).

You can access the User property of the Page property in a Master Page:

Code:
if (Page.User.IsInRole("Managers"))
{
}
Hope this helps,

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 April 18th, 2012, 05:38 PM
Authorized User
 
Join Date: Sep 2011
Posts: 41
Thanks: 3
Thanked 4 Times in 3 Posts
Default

Code:
if (User.IsInRole("Managers"))
{
}

I do not have to have Role Manager enabled to use this feature.
- Imar, thanks for all the replies. I will def try to implement your tips later today. In the meantime, I found the above on page 613. Read the paragraph that begins "The biggest difference ..."

This talks about the two methods above it. Perhaps I read it wrong, but it sounds like for the first option (what I typed in my original post), Role Manager is not enabled. Please read the entire paragraph, it's only 3 sentences ...
 
Old April 18th, 2012, 05:45 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Ah, yes I see. True indeed, but as the last part says, you need an alternative solution that implements roles in order for the check to ever return true.

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 April 20th, 2012, 01:39 AM
Authorized User
 
Join Date: Sep 2011
Posts: 41
Thanks: 3
Thanked 4 Times in 3 Posts
Default

Imar,

Thank you. The solution was easy to implement. I didn't have Roles set up in my web.config to override the machine.config that is used by default. Once I put the Roles info into my web.config and switched the connectstring as you suggested, the code ran fine on both dev and production sides.

As for page 613, well, it's still a little confusing on what is meant and how I read it ... but with the above fixed, I don't have to worry about this for now ... thanks again ... ;-)

- nano
 
Old April 21st, 2012, 03:35 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Page 613 says that you can use roles fro users coming from the RoleManager as well as other systems (such as a custom solution targeting a custom database or credentials store).

Using User.IsInRole would also work against these other systems (provided the roles are assigned to the user correctly), while RoleManager. only works with the RoleManager.

Hope this helps,

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!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Old XSLT broken in production chilly XSLT 4 July 21st, 2011 04:51 PM
Deploying to Production Site DragonLEG BOOK: Beginning ASP.NET 4 : in C# and VB 1 July 1st, 2011 04:22 PM
Controls Work In Dev but not Production qdd ASP.NET 2.0 Basics 1 September 6th, 2007 12:45 PM
~* Installing MSRS in Production Server *~ chakravarthy_vr Reporting Services 0 March 9th, 2006 09:31 PM
values not showing in production server. stewdabaker Classic ASP Databases 1 June 9th, 2004 03:42 PM





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