ASP.NET MVC3: password protect a page - asp.net-mvc-3

Hello in an MVC3 application,
I want to put a password on a page.
The page is accessible from an action link that calls an ActionResult in the controller. And returns the view with the model.
What is the best way or easiest way to add a password to the page.
Something like a popup that shows and you have to put a password and if you put the wrong password you don't see the page (the view is not loaded)
Thanks

You can put a filter on the page's get action.
look at the following link
http://www.asp.net/mvc/tutorials/older-versions/controllers-and-routing/understanding-action-filters-cs

Related

Addressing Codeigniter before and after login

i need to make a login system for my school job, and i want my url on address bar before login and after still the same. Just like facebook, there is url : facebook.com if we're not logged in, and there will be stil facebook.com if we're logged in.
Use HTML5 history API, jQuery,
refer this code examples
example
People use backbone for a one-page app generally.
I assume you are using an authentication library or an authentication system of your own in CodeIgniter.
Inside your default controller you should do something like this (the algorithm)
If user is logged in:
call the layout for the login system
else:
call the main page to be displayed when the user is logged in
For adding other information/pages to it, you could use jquery to replace the body text with the new page.
Where is the new page called from? It can be called from valid CodeIgniter Controllers which provide only the body html.
For example, in your main layout, you could use:
$(document).ready(function(){
$('#button1').click(function(){
$.get("mysite.com/second_page",function(data,status){
$('#main_div').html(data);
});
});
});

Using securesocial services without using its views

I started integrating SecureSocial in my play/scala app, but I don't really like all the redirects it does between it's different views.
example - try to login from it's default login page and if you put in a wrong pass you will be redirected to a different page (url) but with the same login form. the only thing that is different is that there is an error message...
I want a simple login form (user/password provider) at the corner of my main page that submits it's data using ajax, this data is validated on the server and a response is made to either display error message/s or change the window.location.
Next to this form I will put a link to go to a more advanced login page that adds the option to use other providers like fb/twitter etc..
But from that page I also want to use ajax to submit the details and get the response.
I tried to browse into the SecureSocial source but got a little lost in there.
Can any one give me an idea how to use SecureSocial's but without using any of it's views?
NOTE: I'm not interested in customizing their views, It's not just a CSS/design issue, I want to handle the login details Ajaxly and not with normal form submission followed by redirects...
After some more rummaging around in SecureSocial code I got a better understanding of how it operates.
You can use any of the providers you listed in the play.plugins file seperatly to authenthicate the user's info from your own login/auth code. just make sure you send the right parameters that the provider needs.
I liked the way SecureSocial's ProviderController class dynamically decided what provider to use, based on a parameter. But I didn't like the responses it made - redirect.. I wanted to respond to an ajax request with some data and let the client side js handle it.
This is my solution:
pretty much copy all of ProviderController code to my own Auth.scala file (a Controller).
Changed the redirects related to "case ex, case _", kept the redirect on successful auth as it adds the SecureSocial session key related to the user.
Removed all the SecureSocial related routes from my routes file.
Put an additional hidden field with the logintype (userpass/google/fb/etc...) and configured my login ajax post to sent this along with the post to my Auth controller.
If you need more info comment here and I'll edit the answer.

asp.net mvc3 formauthentication,custom role provider-Jquery auto load tabs not working..

I am creating dynamically loading tabs using jquery Ui tabs in my ASP.NET mvc3 project.
Here i have a product page. The product page contains left menus like Customer,Address,Contact,etc..
Here my process is when i click one my left menus, the tab created dynamically with Grid records.
And,
I'm creating a custom role provider and I set a Authorize attribute specifying a role in my controller and it's working just fine, like this:
[Authorize(Roles="SuperAdmin")]
public class SuperAdminController : Controller
...
If one user doens't have access to this controller, And click one of my left menu means,
he's redirected to login page. Its also working fine.
The problem is after the user logged in it didn't redirect the proper page in tab content area.
If my problem not understandable means please let me know..
Thanks Advance...
If you carefully check the URL in the browser, you will see that the URL does not change when you load something by Ajax. That is the point of Ajax actually, you do not load the whole page, right?
Now as the state is not saved when you try to load the content using Ajax, your redirect URL is only the page you loaded initially. That is why you cannot go back to the tab you wanted to load.

accessing master page hyperlink from a different controller

I am using ASP.NET 3.0 MVC with membership provider. I have to make modification to the default implementation we get with membership related code. I have to move LogOff Hyperlink in the master page. Initially this link is in-visible but once authentication is succesfful I need to make it visible. This action will happen from Controller for authentication and I am not sure how to access the hyperlink defined in a master page from a different controller. Any ideas how this could be achieved keeping the spirits of MVC design?
You could create another action in your AccountController to determine if the log off link needs to be displayed. This action has a partial for the html. Call this new action from the master page and check in that action if the log off link needs to be displayed.
#{ Html.RenderAction("displayLogOff", "Account"); }
I'm not sure why you need to make a modification, as this seems to be the default behaviour, but typically you would use a partial view to display the log off hyperlink. This partial view can run an action, and in this action you would send a model to the view which could include a flag for if the user is currently authenticated. Alternatively, you can just check Request.IsAuthenticated in the partial view directly.
I'm not sure I understand. The default implementation already does this. It works regardless of what controller you're using. The reason is that the master page uses a partial page that specifies the method and controller.

mvc application with razor data view engine problems with the url

I create a new mhc application with razor data view engine. I have a problems with the url
Here is my action links
#Html.ActionLink("Home", "Index")
#Html.ActionLink("Schedule", "Schedule")
After I loaded home page my url looks fine
Example: mysiteurl.com
Then I click Schedule link (if I hover I see the correct url http://mysiteurl.com/home/schedule). If I click it as a result my url will http://mysiteurl.com//#/Home/Schedule. I don't know why its adding # sign to my url but it's causing the issue in my application with other pages.
any idea what I'm doing wrong?
Do you have an action method named Schedule? Can you successfully hit it by referencing yoursite.com/Home/Schedule? If not make sure your route is correct.

Resources