Explicitly changing a connection string for MembershipProvider - sharepoint-2007

I am using the following provider to look up users from ADAM. I would be able to like to change the connection string dynamically depending on the type of user. How can I achiev this?
<add name="con1" connectionString="LDAP://con1.url" />
<add name="con2" connectionString="LDAP://con2.url" />
<providers>
<add name="ConnectionProvider" connectionStringName="con1" type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" attributeMapUsername="userPrincipalName" enableSearchMethods="true" />
</providers>

You can get specific sections of the .config by using the ConfigurationManager.GetSection() method (System.Configuration namespace). From here, just apply the logic and select the connection string you want.

Related

Extend Session Timeout

I need to extend the session timeout in my .net mvc application.
I am doing a .get to an action result. It seems to work properly.
Just wanted to confirm that a GET or POST would do the same thing in terms of extending the session timeout.
<sessionState customProvider="DefaultSessionProvider" mode="InProc" timeout="1500">
<providers>
<add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" />
</providers>
</sessionState>
give this in web.config file in your solution..timeout can be changed as per your requirement.

Problems continuing a MVC project with Entity Famework

So I have to work on this project (ASP.NET MVC 4 with Umbraco) that uses Entity Framework and I think UmbracoMembeShipProvider.
Now I have to add Roles to the project. In the DB there's a Users table and some few others. There is no Identity/Roles or the sort in the DB. I tried to create a Roles table and a junction table between Users and Roles but then I couldn't update the models. I made an .edmx schema file and it didn't pick up the junction table, just the Roles table with all the columns pilled up from the junction table.
I tried to approach it by making a Roles entity in the .edmx file and then update the DB via migrations, that also didn't work because the project is stuctued in a way that is has a 'Core' project where all the models are and then a 'Web' project where some other models are. And it gave all heaps of errors.
In the Web project there's a 'Migrations' directory with 2 classes one of which has 2 empty methods (up/down) and one that creates some indexes and then a bunch of commented code.
I'm also quite a newbie in ORMs in general so I don't know how to approach this problem, continuing where the other devs, before me, left off.
In the meantime I'll pick up some tutorials about EF but any help or guidance will be really appreciated.
You need to include the necessary settings in your web.config file which references a connection string pointing to a database where the user/role tables exist. It should look something like this.
<membership defaultProvider="UmbracoMembershipProvider" userIsOnlineTimeWindow="15">
<providers>
<clear />
<add name="UmbracoMembershipProvider"
type="umbraco.providers.members.UmbracoMembershipProvider"
enablePasswordRetrieval="false"
enablePasswordReset="false"
requiresQuestionAndAnswer="false"
defaultMemberTypeAlias="Another Type"
passwordFormat="Hashed" />
<add name="UsersMembershipProvider"
type="umbraco.providers.UsersMembershipProvider"
enablePasswordRetrieval="false"
enablePasswordReset="false"
requiresQuestionAndAnswer="false"
passwordFormat="Hashed" />
</providers>
</membership>
<roleManager enabled="true" defaultProvider="UmbracoRoleProvider">
<providers>
<clear />
<add name="UmbracoRoleProvider" type="umbraco.providers.members.UmbracoRoleProvider" />
</providers>
</roleManager>
<roleManager enabled="true" defaultProvider="UmbracoRoleProvider">
<providers>
<clear />
<add name="UmbracoRoleProvider" type="umbraco.providers.members.UmbracoRoleProvider" />
</providers>
</roleManager>
<appSettings>
<add key="umbracoDbDSN" value="server=localhost;database=MSSM;user id=db_user;password=password" />

Error Unable connect to SQL Server when add <roleManager enabled="true">

When I add
<roleManager enabled="true"></roleManager>
to my web.config, I get an error
Unable to connect to SQL Server database
occurs on this line of code:
System.Web.Security.Roles.AddUserToRole(m.UserName, "admin");
I added this to the web.config and it solved my problem:
<system.web>
<roleManager enabled="true" defaultProvider="CustomizedRoleProvider">
<providers>
<add name="CustomizedRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="DefaultConnection" />
</providers>
</roleManager>
</system.web>
I had the exact same error when I had enabled believing I was enabling ASP.NET Identity 2. They are not the same! The enabled an old version of identity management which uses a different table structure to ASP.NET Identity 2 (which doesn't need "enabling" by the way - it's just there).
check the connection String.
If you are intentionally using the old role-manager and still getting the error you might be looking at the default localdb instead of your database, in which case you can modify to point at any connection string you want:
<roleManager
enabled="true"
cacheRolesInCookie="true"
defaultProvider="OurSqlRoleProvider"
>
<providers>
<add
connectionStringName="DefaultConnection"
applicationName="/"
name="OurSqlRoleProvider"
type="System.Web.Security.SqlRoleProvider" />
</providers>
</roleManager>
If you are are after using ASP.NET Identity 2, here's an article on it:
http://johnatten.com/2014/04/20/asp-net-mvc-and-identity-2-0-understanding-the-basics/

URL Routing Not Working (asp.net 4.5, webforms)

I've been trying to figure out how to get URL routing to work on my box all evening. I'm pretty sure I'm doing things according to the online tutorials (http://msdn.microsoft.com/en-us/library/vstudio/dd329551%28v=vs.100%29.aspx) but for some reason it's not working.
This is what I currently type in the address bar: /MA1/DoSurvey.aspx?id=42
But I want the URL to work like this: /MA1/DoSurvey/42
According to the tutorial I have to modify:
1: Global.asax.cs by adding
RouteConfig.RegisterRoutes(RouteTable.Routes);
into the Application_Start method
2: RouteConfig.cs by adding
routes.MapPageRoute("","DoSurvey/{id}","~/MA1/DoSurvey.aspx");
into the RegisterRoutes method
3: Add
using System.Web.Routing;
as a reference in the DoSurvey.aspx page and then
4: Grab the querystring variable by using
string SurveyIdQueryStringValue = Page.RouteData.Values["id"] as string;
in the DoSurvey.aspx page
what am I missing?
I Add this code to web.config and everything worked fine, try it
<modules runAllManagedModulesForAllRequests="true">
<remove name="UrlRoutingModule" />
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
</modules>
<handlers>
<add name="UrlRoutingHandler" preCondition="integratedMode" verb="*" path="UrlRouting.axd" type="System.Web.HttpForbiddenHandler, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />

Tags in Web.Config?

In the project's Web.Config of MVC, there are tags such as
<profile defaultProvider="DefaultProfileProvider">
<providers>
<add name="DefaultProfileProvider"
type="System.Web.Providers.DefaultProfileProvider, System.Web.Providers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
connectionStringName="OfficeData" applicationName="/" />
</providers>
</profile>
<membership defaultProvider="DefaultMembershipProvider">
...
</membership>
<roleManager defaultProvider="DefaultRoleProvider">
...
</roleManager>
What are they? And what is their purpose?
Those elements are the basic configuration for ASP.Net Membership, the default authentication/authorization system for ASP.Net. There's lots of configuration you'll want to do, but at a high level you have three sets of configuration:
profile - a system for saving user related profile information (By default a weird data schema is used, and should be avoided)
membership - the central place for configuring authentication (passwords storage, resetting, etc.)
roles - your users will be grouped into roles within you app, this is where you configure that
ASP.Net Membership is solid, but dated and inflexible. The new standard is ASP.Net Identity

Resources