How do I make my existing MVC application function like the project template application? [warning: noob level questions]

91 views
Skip to first unread message

Johnny

unread,
Mar 18, 2010, 12:55:16 AM3/18/10
to DotNetOpenAuth
Hello,

I'm new to DotNetOpenAuth and new to MVC programming in general.
I have stared working on an MVC site.
I have decided I want to use OpenID for my login management.

I just created a test project based on the MVC project template.
This looks great.
Can you point me in the right direction of making my site's login/user
management function like the project template site does?
Do I need to copy all the files in the "RelyingPartyLogic" section to
my project, create the necessary tables in my database to mimic the
project template tables (and change pointers/connection strings), then
alter my AccountController to mimic one in the project template? (and
go from there?)

Before I start tearing my project apart I want to make sure I'm on the
right path.

Also, how do I get to Role management pages in the project template
site?

Thanks!

Andrew Arnott

unread,
Mar 18, 2010, 2:18:52 AM3/18/10
to dotnetopenid
Hi Johnny,

I'm excited for the step you're taking.  I'll see what I can do to help.
Inline...

On Wed, Mar 17, 2010 at 9:55 PM, Johnny <johnny...@gmail.com> wrote:
I just created a test project based on the MVC project template.
This looks great.
Can you point me in the right direction of making my site's login/user
management function like the project template site does?

So I take it you've invested enough time in your own project that you'd rather move the template code into your project rather than the other way around.  And what version of the project template are you going off of?  There are a few very different versions out there.  Can you give me the full version number like (v3.4.1.12345)?
 
Do I need to copy all the files in the "RelyingPartyLogic" section to
my project, create the necessary tables in my database to mimic the
project template tables (and change pointers/connection strings), then
alter my AccountController to mimic one in the project template?  (and
go from there?)

I recommend you just copy the entire RelyingPartyLogic project into your solution and keep it as a class library.  Creating the database tables should be fairly easy as the RPLogic project has a SQL schema creation script in it.  Then just look inside the Content, Controllers, Scripts, and Views directories to make sure you have everything that you need by either copying entire files or individual actions.
 

Before I start tearing my project apart I want to make sure I'm on the
right path.

Good.  And make sure you're either in version control or you've backed up your project before you start ripping it apart.
 

Also, how do I get to Role management pages in the project template
site?

There aren't any.  Role management and other site administration isn't a feature of the template [yet].  You'll have to create those pages yourself and/or directly manipulate the data in your database to control this.  Once the role information is in the database though, the project template knows how to apply those roles to the users that log in.


Thanks!

Johnny

unread,
Mar 18, 2010, 12:37:12 PM3/18/10
to DotNetOpenAuth
Thanks for replying.

The version number is 3.4.1.10044
Is this the latest version?

Our project isn't so big yet that we can't move our code into the
project template project.
However, our project is MVC2.
Will converting the project template to MVC2 break anything?

Thanks.

On Mar 18, 2:18 am, Andrew Arnott <andrewarn...@gmail.com> wrote:
> Hi Johnny,
>
> I'm excited for the step you're taking.  I'll see what I can do to help.
> Inline...
>

Andrew Arnott

unread,
Mar 18, 2010, 1:03:29 PM3/18/10
to dotnet...@googlegroups.com
MVC2 will work fine with the project template. You just have to change the referenced assemblies to the new version to take advantage of the MVC2 features.  

Version v3.4.1.10044 is the latest official release, although if you're on VS2010 you can download a newer pre-release from the Visual Studio Gallery that has a much nicer login page.  v3.4.2 is expected to come out this weekend, which will make it available to the VS2008 crowd as well.

The differences between MVC1 and MVC2 generated web projects seem so small that I suspect it would be easier for you to "upgrade" the results of the DNOA project template to MVC2 standards that migrate the results of the project template into an empty MVC2 project.
--
Andrew Arnott
"I [may] not agree with what you have to say, but I'll defend to the death your right to say it." - S. G. Tallentyre

David Christiansen

unread,
Mar 18, 2010, 1:11:40 PM3/18/10
to dotnet...@googlegroups.com

Short and simple. I can confirm that there are no issues experienced when working under ASP.NET MVC2.

 

Enjoy!

 

---

Kind Regards,

David Christiansen | Chief Software Architect @ www.netidme.com

Johnny

unread,
Mar 18, 2010, 11:51:42 PM3/18/10
to DotNetOpenAuth
OK, I downloaded and installed version 3.4.1.10051, found
http://visualstudiogallery.msdn.microsoft.com/en-us/a527c9a4-6032-43ce-9284-d7e3174deb56

However, when I try to create a new project, I get this error:
"A problem was encountered creating the sub project 'OpenID'. The
project file 'C:\users\Johnny\AppData\Local\Temp\adfkadfa.mqi\Temp
\OpenID.csproj' cannot be opened.

The project type is not supported by this installation"


I hope this isn't too generic of an error.
I did some googling but didn't find anything that helped.

Any ideas?
I am in VS2010.
I have .NET framework 4.0 installed.
I have MVC 2 installed.

Thanks.

David Christiansen

unread,
Mar 19, 2010, 5:33:55 AM3/19/10
to dotnet...@googlegroups.com
Hi Johnny,
You should first check out http://www.dotnetopenauth.net/developers/quickstart-environment/ and ensure you have all the prerequisites installed. Note that at the time of writing ASP.NET MVC was version 1, so it is possible that the error you are receiving is down to the project being an ASP.NET MVC 1 project. As I have 1 and 2 installed on my machine I have not encountered this issue.

Let us know how you get on.

---
Kind Regards,
David Christiansen | Chief Software Architect @ www.netidme.com

Thanks.

To unsubscribe from this group, send email to dotnetopenid+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.

Johnny

unread,
Mar 19, 2010, 8:46:15 AM3/19/10
to DotNetOpenAuth
That was it.
I installed StyleCop and now I can create the project.
Thanks!

One more kind-of off topic question:
I found a newer version of the project template than the one I just
installed (http://visualstudiogallery.msdn.microsoft.com/en-us/
81153747-70d7-477b-b85a-0374e7edabef)

Now when I go to add a new project, there are two "ASP.NET MVC OpenID-
InfoCard RP" templates to choose from. There's no way to tell which
version is which. How can I remove the older template? Where are
they stored? I've looked in "\My Documents\Visual Studio
2010\Templates\ProjectTemplates" and they aren't there.

Thanks

On Mar 19, 5:33 am, David Christiansen
<david.christian...@netidme.com> wrote:
> Hi Johnny,
> You should first check outhttp://www.dotnetopenauth.net/developers/quickstart-environment/and ensure you have all the prerequisites installed. Note that at the time of writing ASP.NET MVC was version 1, so it is possible that the error you are receiving is down to the project being an ASP.NET MVC 1 project. As I have 1 and 2 installed on my machine I have not encountered this issue.


>
> Let us know how you get on.
>
> ---
> Kind Regards,
> David Christiansen | Chief Software Architect @www.netidme.com
>
>
>
> -----Original Message-----
> From: dotnet...@googlegroups.com [mailto:dotnet...@googlegroups.com] On Behalf Of Johnny
> Sent: 19 March 2010 03:52
> To: DotNetOpenAuth
> Subject: [dotnetopenid] Re: How do I make my existing MVC application function like the project template application? [warning: noob level questions]
>

> OK, I downloaded and installed version 3.4.1.10051, foundhttp://visualstudiogallery.msdn.microsoft.com/en-us/a527c9a4-6032-43c...

Andrew Arnott

unread,
Mar 19, 2010, 9:00:01 AM3/19/10
to dotnetopenid
Hi Johnny,

Actually the two versions you link to are slightly different: one has "MVC" in the name, and the other builds a web forms project instead of MVC.  The MVC one is newer, as you say.  Can you confirm whether "MVC" distinguishes the two project templates in your New Project dialog?

You can remove VS Gallery project templates via the VS Extension Manager (usually the second-to-last icon on the standard toolbar).

--
Andrew Arnott
"I [may] not agree with what you have to say, but I'll defend to the death your right to say it." - S. G. Tallentyre


Johnny

unread,
Mar 19, 2010, 3:13:53 PM3/19/10
to DotNetOpenAuth
Actually, there are two "ASP.NET MVC OpenID-InfoCard RP" and two
"ASP.NET OpenID-InfoCard RP"

But I think I maybe fixed it.
I found "MvcRelyingParty.zip" and "WebFormsRelyingParty.zip" in "C:
\Users\Johnny\Documents\Visual Studio 2010\Templates\ProjectTemplates
\Visual C#\Web"

If I delete/move the files, I'm down to one each (MVC and webforms)
projects in the New Project dialog.

Thanks.

On Mar 19, 9:00 am, Andrew Arnott <andrewarn...@gmail.com> wrote:
> Hi Johnny,
>

Johnny

unread,
Mar 22, 2010, 12:31:16 AM3/22/10
to DotNetOpenAuth
OK, I'm getting closer.
I'm trying to merge the projects.
Of course, every error I "fix" creates 10 more errors.
Now I'm getting this one. My site builds/runs. But when I click
"Register/Login", the popup starts to load, then I get this error:
img693 [dot] imageshack [dot] us/img693/3662/error1pc.jpg

Any idea what's causing it?

Thanks.
(Sorry about the unfriendly URL. Google doesn't seem to want me to
post a URL)

Andrew Arnott

unread,
Mar 22, 2010, 11:59:21 AM3/22/10
to dotnetopenid
A stack trace on that exception would be helpful.

--
Andrew Arnott
"I [may] not agree with what you have to say, but I'll defend to the death your right to say it." - S. G. Tallentyre


To unsubscribe from this group, send email to dotnetopenid+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.

Johnny

unread,
Mar 22, 2010, 12:18:29 PM3/22/10
to DotNetOpenAuth
Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not
set to an instance of an object.

Source Error:


Line 9: };
Line 10: %>
Line 11: <%= Html.OpenIdSelectorScripts(this.Page, null, options)%>


Stack Trace:


[NullReferenceException: Object reference not set to an instance of an
object.]
DotNetOpenAuth.Mvc.OpenIdHelper.OpenIdSelectorScripts(HtmlHelper
html, Page page, OpenIdSelector selectorOptions, OpenIdAjaxOptions
additionalOptions) in c:\Users\andarno\git\dotnetopenid\src
\DotNetOpenAuth\Mvc\OpenIdHelper.cs:131
ASP.views_auth_logonscripts_ascx.__Render__control1(HtmlTextWriter
__w, Control parameterContainer) in e:\_Dev_\Projects\MVC2OpenID
\MVC2OpenID\MVC2OpenID\Views\Auth\LogOnScripts.ascx:11
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer,
ICollection children) +256
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19
System.Web.UI.Control.Render(HtmlTextWriter writer) +10
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer,
ControlAdapter adapter) +27
System.Web.UI.Control.RenderControl(HtmlTextWriter writer,
ControlAdapter adapter) +99
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer,
ICollection children) +134
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19
System.Web.UI.Page.Render(HtmlTextWriter writer) +29
System.Web.Mvc.ViewPage.Render(HtmlTextWriter writer) +59
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer,
ControlAdapter adapter) +27
System.Web.UI.Control.RenderControl(HtmlTextWriter writer,
ControlAdapter adapter) +99
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
+1266

Thanks.

Andrew Arnott

unread,
Mar 22, 2010, 12:32:55 PM3/22/10
to dotnetopenid
Ah.  I need to go through and improve the error reporting of that method.  I suspect though that you're missing the "OpenIdDiscover" named route in your global.asax.cs file. 

--
Andrew Arnott
"I [may] not agree with what you have to say, but I'll defend to the death your right to say it." - S. G. Tallentyre


To unsubscribe from this group, send email to dotnetopenid+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.

Johnny

unread,
Mar 22, 2010, 2:28:00 PM3/22/10
to DotNetOpenAuth
Thanks, that was it. I had copied over my Global file from my other
project.

Now I can build the site. I click Login. The popup comes up. I
click Google and I'm logged in!
But how can someone else login from the same browser? My wife came in
the room and I wanted to show her.
I clicked Log Off. Then I clicked Login. But the same thing
happened. It automatically logs me in. Is there a way to switch users
(besides opening another browser, going to google.com and logging out
there)?

So, I logged out of google.
I clicked Login. I typed her username and password and I get this
error:

Sequence contains no elements

Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: Sequence contains
no elements

Source Error:


Line 7: Welcome <b>
Line 8: <%
Line 9: var authToken =
Database.DataContext.AuthenticationTokens.Include("User").First(token
=> token.ClaimedIdentifier == Page.User.Identity.Name);
Line 10: if (!string.IsNullOrEmpty(authToken.User.EmailAddress)) {
Line 11:
Response.Write(HttpUtility.HtmlEncode(authToken.User.EmailAddress));

Source File: e:\path\Views\\Shared\LogOnUserControl.ascx Line: 9

Stack Trace:


[InvalidOperationException: Sequence contains no elements]
System.Linq.Enumerable.First(IEnumerable`1 source) +731024

System.Data.Objects.ELinq.ObjectQueryProvider.<GetElementFunction>b__0(IEnumerable`1
sequence) +40

System.Data.Objects.ELinq.ObjectQueryProvider.ExecuteSingle(IEnumerable`1
query, Expression queryRoot) +59

System.Data.Objects.ELinq.ObjectQueryProvider.System.Linq.IQueryProvider.Execute(Expression
expression) +109
System.Linq.Queryable.First(IQueryable`1 source, Expression`1
predicate) +301

ASP.views_shared_logonusercontrol_ascx.__Render__control1(HtmlTextWriter
__w, Control parameterContainer) in e:\path\Views\Shared
\LogOnUserControl.ascx:9


System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer,
ICollection children) +256
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19
System.Web.UI.Control.Render(HtmlTextWriter writer) +10
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer,
ControlAdapter adapter) +27
System.Web.UI.Control.RenderControl(HtmlTextWriter writer,
ControlAdapter adapter) +99
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer,
ICollection children) +134
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19
System.Web.UI.Page.Render(HtmlTextWriter writer) +29
System.Web.Mvc.ViewPage.Render(HtmlTextWriter writer) +59
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer,
ControlAdapter adapter) +27
System.Web.UI.Control.RenderControl(HtmlTextWriter writer,
ControlAdapter adapter) +99
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
+1266

Any ideas?

Thanks so much for all your help.

> ...
>
> read more »

Johnny

unread,
Mar 22, 2010, 2:46:06 PM3/22/10
to DotNetOpenAuth
Fixed that last error.
I had my my Web.config file all messed up. (I overwrote it too from
my other projects Web.config file).

> System.Data.Objects.ELinq.ObjectQueryProvider.<GetElementFunction>b__0(IEnu merable`1

> ...
>
> read more »

Andrew Arnott

unread,
Mar 22, 2010, 3:33:01 PM3/22/10
to dotnetopenid
As far as being able to log yourself in, then your wife in, without having explicitly logged out of Google already... that's something of a usability whole in SSO in general, and it impacts OpenID and this UI.  OpenID does not provide a mechanism to force a log out of Google.  So in general users must know that they should log out of their OP before leaving a computer.


--
Andrew Arnott
"I [may] not agree with what you have to say, but I'll defend to the death your right to say it." - S. G. Tallentyre


> ...
>
> read more »

Øyvind Sean Kinsey

unread,
Mar 22, 2010, 4:32:47 PM3/22/10
to dotnet...@googlegroups.com
Or you can use the PAPE extension to force the user to re-authenticate to google if your last sign-in was more than x minutes ago..
That is one of the few ways to workaround that issue.


Øyvind Sean Kinsey
oyv...@kinsey.no
http://kinsey.no/blog/index.php/about/
Reply all
Reply to author
Forward
0 new messages