7 Replies - 1149 Views - Last Post: 21 April 2016 - 08:50 AM

#1 Coding in the name of  Icon User is offline

  • D.I.C Regular

Reputation: 67
  • View blog
  • Posts: 291
  • Joined: 07-July 10

Authentication

Posted 25 March 2016 - 11:39 AM

Hi I'm trying to setup authentication for a website I'm running with IIS 8. I'm using the default pages and code you get with the web forms template in VS 2015. I've been looking up tutorials but I'm finding it confusing. As far as I understand the pages in ~/Account/ except Login.aspx need a login to be seen. If I use a MySQL database to store username, password and role information, what do I need to do to set that up? Can someone point me to a straightforward tutorial that's based on editing what the web forms template sets up for you? Thanks.

So far I've enabled forms authentication for the app under default website in IIS manager. I've enabled anonymous authentication and windows authentication in the VS project, I'm not sure if I need to enable windows authentication to use forms authentication.

http://www.asp.net/i...torage-provider
This website seems to have what I need but it's for MVC, can I use this in my web forms project?

This post has been edited by Coding in the name of: 26 March 2016 - 10:59 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Authentication

#2 Coding in the name of  Icon User is offline

  • D.I.C Regular

Reputation: 67
  • View blog
  • Posts: 291
  • Joined: 07-July 10

Re: Authentication

Posted 27 March 2016 - 01:00 PM

Doesn't seem like I can edit the original post any more.

I found this website which seems to have everything I need. It's an Easter miracle!
http://blog.develope...-2-1-for-mysql/
Was This Post Helpful? 0
  • +
  • -

#3 Coding in the name of  Icon User is offline

  • D.I.C Regular

Reputation: 67
  • View blog
  • Posts: 291
  • Joined: 07-July 10

Re: Authentication

Posted 19 April 2016 - 09:01 AM

Unfortunately I'm still lost on this. I don't know whether I should use Membership or Identity, or what the differences in implementation between either should be. I'm not sure how my Web.config should look because of this confusing section:

<system.web>
  <authentication mode="Forms" />
  <compilation debug="true" targetFramework="4.5.2" />
  <httpRuntime targetFramework="4.5.2" />
</system.web>
<system.webServer>
  <modules>
    <remove name="FormsAuthentication" />
  </modules>
</system.webServer>


What I really want is to be able to use a MySQL database to store identities with roles working and, if possible, to store other entity framework data in another MySQL DB. And I'd like to use as much of the code that is generated for me in the template as possible, making minimal changes.

I hope someone can explain this to me in words I can understand. Thanks.

This post has been edited by Coding in the name of: 19 April 2016 - 09:02 AM

Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 13566
  • View blog
  • Posts: 54,122
  • Joined: 12-June 08

Re: Authentication

Posted 19 April 2016 - 09:04 AM

Membership is the old ASP way.. the new is Identity. Entity framework/MVC and all that jazz.
Was This Post Helpful? 1
  • +
  • -

#5 Coding in the name of  Icon User is offline

  • D.I.C Regular

Reputation: 67
  • View blog
  • Posts: 291
  • Joined: 07-July 10

Re: Authentication

Posted 20 April 2016 - 02:37 AM

I managed to get my Entities stored in a MySql DB and it was a lot more painless than I thought. I just added the db context like this:

[DbConfigurationType(typeof(MySqlEFConfiguration))]
public class SurveyDBContext : DbContext
{
    public SurveyDBContext()
        : base("SurveyConnection")
    {
        Database.SetInitializer(new SurveyDbInitializer());
    }

    public DbSet<CERO> Ceros { get; set; }
}


And added the provider like so:

<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" />


The only remaining problem is authentication. I've changed the DefaultConnection string to point to my identity MySQL DB but when I try to use the register/login pages I get errors saying that table 'aspnet*' doesn't exist. I think it's looking for membership tables instead of identity tables, so I just need to figure out this last bit now. I'd be very grateful if you could give me some direction on this.

Edit:
I had the tables backwards. I let the ApplicationDbContext auto create the tables and it's all working. Easier than I thought but I kept finding conflicting information, probably for different versions or something. The last thing to get working will be roles.

When I try to set the default provider to MySQLMembershipProvider it tells me I need to add it to the trusted section of a config file. But since it has the name Membership in it, can you tell me if this is the right thing or is it different for Identities?

This post has been edited by Coding in the name of: 20 April 2016 - 04:37 PM

Was This Post Helpful? 0
  • +
  • -

#6 Coding in the name of  Icon User is offline

  • D.I.C Regular

Reputation: 67
  • View blog
  • Posts: 291
  • Joined: 07-July 10

Re: Authentication

Posted 21 April 2016 - 02:58 AM

I've tried using the ASP.NET Web Site Administration Tool to set MySQLMembershipProvider as the app's membership provider and MySQLRoleProvider as the role provider. When I try to use the security tab in the admin tool I get this error: "There is a problem with your selected data store. This can be caused by an invalid server name or credentials, or by insufficient permission. It can also be caused by the role manager feature not being enabled."

Setting allowUntrustedProviders="true" in administration.config system.webServer/management/trustedProviders doesn't seem to allow the MySQL providers.

This post has been edited by Coding in the name of: 21 April 2016 - 05:00 AM

Was This Post Helpful? 0
  • +
  • -

#7 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 13566
  • View blog
  • Posts: 54,122
  • Joined: 12-June 08

Re: Authentication

Posted 21 April 2016 - 07:49 AM

I am unclear where you are or what your are asking.

http://www.asp.net/i...-mysql-provider
Was This Post Helpful? 0
  • +
  • -

#8 Coding in the name of  Icon User is offline

  • D.I.C Regular

Reputation: 67
  • View blog
  • Posts: 291
  • Joined: 07-July 10

Re: Authentication

Posted 21 April 2016 - 08:50 AM

The MySQL identity database is working, I can register and login to my website. I want to control access by using authorization roles, but I don't know how I can create and administrate these roles. I am serving the website with IIS 8 on a Windows Server 2012 r2 computer.

I believe .Net roles is the right section to look in for this but I get the error you can see here (http://imgur.com/a/y68cc). I also get this error when I click on the .NET Users section which has the default provider set to MySQLMembershipProvider (.NET Roles default provider is MySQLRoleProvider). I don't get this error going into the .NET Profile section which is using MySQLProfileProvider as default provider.

I have also used the ASP.NET Web Site Administration Tool to set the Membership and Role providers for my app to MySQLMembershipProvider and MySQLRoleProvider. The security tab shows the error you can see in the third image in the album.

I have tried to make these providers trusted by changing C:\Windows\System32\inetsrv\Config\administration.config's system.webServer section to this:

<system.webServer>
        <management>
            <authentication defaultProvider="ConfigurationAuthenticationProvider">
                <providers>
                  <add name="ConfigurationAuthenticationProvider" type="Microsoft.Web.Management.Server.ConfigurationAuthenticationProvider, Microsoft.Web.Management, Version=7.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
                </providers>
            </authentication>

            <authorization defaultProvider="ConfigurationAuthorizationProvider">
                <providers>
                    <add name="ConfigurationAuthorizationProvider" type="Microsoft.Web.Management.Server.ConfigurationAuthorizationProvider, Microsoft.Web.Management, Version=7.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
                </providers>
            </authorization>
            
            <trustedProviders allowUntrustedProviders="false">
                <add type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
                <add type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
                <add type="System.Web.Security.WindowsTokenRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
				<add type="MySql.Web.Security.MySqlMembershipProvider, MySql.Web, Version=6.9.8.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
				<add type="MySql.Web.Security.MySqlRoleProvider, MySql.Web, Version=6.9.8.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
            </trustedProviders>
        </management>
    </system.webServer>


And by adding MySql.Web.dll, MySql.Data.dll, and MySql.Data.Entity.EF6.dll to the GAC. (http://i.imgur.com/W25ah2D.png).

I have done everything in those instructions except for the custom migration history context, MySQL doesn't have the 255 varchar limit any more so it doesn't seem necessary.

My app's web.config has this for its entityFramework section:
<entityFramework>
    <providers>
      <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" />
    </providers>
  </entityFramework>


and these sections as well:
<system.web>
    <authentication mode="Forms" />
    <compilation targetFramework="4.5.2" />
    <httpRuntime targetFramework="4.5.2" />
    <profile defaultProvider="MySQLProfileProvider" />
    <roleManager defaultProvider="MySQLRoleProvider" enabled="true" />
    <trust level="Full" />
    <membership defaultProvider="MySQLMembershipProvider" />
  </system.web>
  <system.data>
	<DbProviderFactories>
	  <remove invariant="MySql.Data.MySqlClient"></remove>
	  <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.9.8.0" />
	</DbProviderFactories>
  </system.data>
  <system.webServer>
    <modules>
      <remove name="FormsAuthenticationModule" />
    </modules>
  </system.webServer>


According to this post I need to use an ASP.NET Configuration Tool within Visual Studio, but I can't find this in VS Community.

Edit:
Apparently the solution is to make your own administration tool. http://www.dotnetfun...dentity-for-mvc

This one's finally solved. Thanks again.

This post has been edited by Coding in the name of: 21 April 2016 - 12:20 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1