Note that there are some explanatory texts on larger screens.

plurals
  1. POAdding profile values for auto-generated user
    text
    copied!<p>I'm creating a ASP.NET MVC 3.0 website, and have a couple of different database initializations based on whether the site is intended for development, testing, or production. I'm stuck on the testing initialization, as I'm trying to get a test user created. I can get the user to create just fine, however when I try to add some profile values, I get: System.Web.HttpException: Request is not available in this context. Is there a way to add Profile values in a situation where the request isn't going to be available?</p> <p>Following code is what is being run:</p> <pre><code> protected void Application_Start() { AreaRegistration.RegisterAllAreas(); RegisterGlobalFilters(GlobalFilters.Filters); RegisterRoutes(RouteTable.Routes); if (ApplicationServices.GetInitialCatalog() != "tasktracker") { Database.SetInitializer(new TaskTrackerDropCreateDatabaseIfModelChanges()); } else { Database.SetInitializer(new TaskTrackerCreateDatabaseIfNotExists()); } using (var db = new TaskTrackerContext()) { db.Database.Initialize(false); } } public class TaskTrackerDropCreateDatabaseIfModelChanges : DropCreateDatabaseIfModelChanges&lt;TaskTrackerContext&gt; { protected override void Seed(TaskTrackerContext context) { // Set up the membership, roles, and profile systems. ApplicationServices.InstallServices(SqlFeatures.Membership | SqlFeatures.Profile | SqlFeatures.RoleManager); // Create the default accounts and roles. if (ApplicationServices.GetInitialCatalog() == "tasktracker_testing") { if (Membership.GetUser("testuser", false) == null) { Membership.CreateUser("testuser", "password", "testuser@test.com"); MembershipUser user = Membership.GetUser("testuser", false); user.IsApproved = true; var profile = ProfileBase.Create("testuser"); profile.SetPropertyValue("FirstName", "test"); profile.SetPropertyValue("LastName", "user"); profile.SetPropertyValue("TimeZone", "US Mountain Standard Time"); profile.Save(); } } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload