I've been using the "Starter Site" template to create a site that requires a user to login to access the content. Here is the problem:
I work in a library and the users are going to be coming from the library's online catalog. All I can do with that site is put a link in a specific record there. Once the user clicks the link they are taken to a page in "Starter Site", but they must first
login, only certain people are allowed to access this content. after they login it takes them back to the "Starter Site" homepage, I do not want that to happen. What i want to do is have the user continue to the page they requested while they were in the online
catalog, after logging in. Also the pages in starter site are going to be dynamic pages using variable urls.
In the Starter Site sample, you will find a Login.cshtml page in which the user is redirected to the page they first attempted to access when they have successfully logged in. The code looks for the ReturnUrl parameter in the query string and uses RedirectLocal
to transfer the user to that page:
// Attempt to login to the Security object using provided creds
if (WebSecurity.Login(username, password, rememberMe)) {
var returnUrl = Request.QueryString["ReturnUrl"];
if (returnUrl.IsEmpty()){
Response.Redirect("~/");
} else {
Context.RedirectLocal(returnUrl);
}
}
Yeah thats the page i'm using and that works fine if the user starts on "Starter Site". but my problem is that the user will be clicking on the link from a separate site. thats something i will not be able to change. here's a complete example of what I want:
1. User finds a book in our online catalog (separate site from "Starter Site")
2. The book's page has a link to the "online version" of the book and the user clicks the link (http://librarywebsite.com/Resources.cshtml?id=2)
3. They are taken to "Starter Site" where they are asked to logon.
4. After they login they are taken straight to http://librarywebsite.com/Resources.cshtml?id=2 and not the "Starter Site" Homepage.
So long as you have protected Resources.cshtml from unauthorised access by using WebSecurity.RequireAuthenticatedUser(), the user should be directed to Logon.cshtml, with a querystring as follows:
i changed the folder name from Account to acc and doesn't work. It shows HTTP Error 404.0 - Not Found beacuse in the url is still /Account/Login?ReturnUrl
How is this related to Account folder, how to change if i change or rename the folder?
The Account folder is the default location for the Login page.
If you want to change this setting you must add an appSettings section into the configuration section of your web.config file with a content like this:
smrt85
Member
12 Points
9 Posts
request page, Authenticate (login), continue to page requested
Dec 21, 2011 03:40 PM|LINK
Hi,
I've been using the "Starter Site" template to create a site that requires a user to login to access the content. Here is the problem:
I work in a library and the users are going to be coming from the library's online catalog. All I can do with that site is put a link in a specific record there. Once the user clicks the link they are taken to a page in "Starter Site", but they must first login, only certain people are allowed to access this content. after they login it takes them back to the "Starter Site" homepage, I do not want that to happen. What i want to do is have the user continue to the page they requested while they were in the online catalog, after logging in. Also the pages in starter site are going to be dynamic pages using variable urls.
authenticate RAZOR
Mikesdotnett...
All-Star
155645 Points
19985 Posts
Moderator
MVP
Re: request page, Authenticate (login), continue to page requested
Dec 21, 2011 04:20 PM|LINK
In the Starter Site sample, you will find a Login.cshtml page in which the user is redirected to the page they first attempted to access when they have successfully logged in. The code looks for the ReturnUrl parameter in the query string and uses RedirectLocal to transfer the user to that page:
// Attempt to login to the Security object using provided creds if (WebSecurity.Login(username, password, rememberMe)) { var returnUrl = Request.QueryString["ReturnUrl"]; if (returnUrl.IsEmpty()){ Response.Redirect("~/"); } else { Context.RedirectLocal(returnUrl); } }That seems to be what you want, isn't it?
authenticate RAZOR
Web Pages CMS | My Site | Twitter
smrt85
Member
12 Points
9 Posts
Re: request page, Authenticate (login), continue to page requested
Dec 21, 2011 04:37 PM|LINK
Yeah thats the page i'm using and that works fine if the user starts on "Starter Site". but my problem is that the user will be clicking on the link from a separate site. thats something i will not be able to change. here's a complete example of what I want:
1. User finds a book in our online catalog (separate site from "Starter Site")
2. The book's page has a link to the "online version" of the book and the user clicks the link (http://librarywebsite.com/Resources.cshtml?id=2)
3. They are taken to "Starter Site" where they are asked to logon.
4. After they login they are taken straight to http://librarywebsite.com/Resources.cshtml?id=2 and not the "Starter Site" Homepage.
Thanks for your help.
smrt85
Member
12 Points
9 Posts
Re: request page, Authenticate (login), continue to page requested
Dec 21, 2011 04:44 PM|LINK
oh and sorry http://librarywebsite.com/Resources.cshtml?id=2 is part of "Starter Site"
Mikesdotnett...
All-Star
155645 Points
19985 Posts
Moderator
MVP
Re: request page, Authenticate (login), continue to page requested
Dec 21, 2011 07:03 PM|LINK
So long as you have protected Resources.cshtml from unauthorised access by using WebSecurity.RequireAuthenticatedUser(), the user should be directed to Logon.cshtml, with a querystring as follows:
Logon?ReturnUrl=Resources.cshtml%3fid%3d2
Web Pages CMS | My Site | Twitter
smrt85
Member
12 Points
9 Posts
Re: request page, Authenticate (login), continue to page requested
Dec 21, 2011 07:31 PM|LINK
Hah ok. In Resources.cshtml at the top of the page i had:
@if (!WebSecurity.IsAuthenticated) {
Response.Redirect("~/Account/Login");
}
and i switched it with:
@{WebSecurity.RequireAuthenticatedUser();}
Thanks for all your help!
dow7
Member
738 Points
452 Posts
Re: request page, Authenticate (login), continue to page requested
Feb 15, 2012 01:22 PM|LINK
Hi,
i changed the folder name from Account to acc and doesn't work. It shows HTTP Error 404.0 - Not Found beacuse in the url is still /Account/Login?ReturnUrl
How is this related to Account folder, how to change if i change or rename the folder?
Thank you
GmGregori
Contributor
5564 Points
749 Posts
Re: request page, Authenticate (login), continue to page requested
Feb 15, 2012 04:19 PM|LINK
The Account folder is the default location for the Login page.
If you want to change this setting you must add an appSettings section into the configuration section of your web.config file with a content like this:
<appSettings> <add key="loginUrl" value="~/acc/Login" /> </appSettings>