I am developing an asp.net mvc application and have created my custom user database and registration procedure (need email verification). Can I use FormsAuthentication.SetAuthCookie with my own login procedure, without dealing with asp.net's membership provider? Will doing so work with the [Authorize] attribute?
Yes, you can use FormsAuthentication.SetAuthCookie within your own login procedure, in fact, that's what the default asp.net mvc template uses.
[Authorize] will work since FormsAuthentication.SetAuthCookie populates HttpContext.User.Identity.IsAuthenticated to true.
Related
I'm implement aspnet identity with my MVC5 project. I have configured my project to use cookie authentication, form authentication and external authentication (facebook and google). Everything work fine.
Now i have a requirement to log whenever user log in system and i need to do some further logic. For the form authentication and external authentication i have a controller action that i can add my logic. However for the case user just come back system via cookie, how do i handle it?
I'm sure there's a better way to handle this, but a basic method would be to track all activity by the user, and then use timestamps to determine when a user was last active on your site.
Discussed here: Track user activity/actions for an asp.net mvc website?
OnExecuting filters here: https://msdn.microsoft.com/en-us/library/gg416513%28VS.98%29.aspx
I got MVC 5 application Using asp.net identity for authentication works fine.
I want my MVC 5 application to use authentication from an already existing application with Traditional Asp.net authentication
I want Existing Traditional Asp.net authentication application to be used as single Sign-on and mvc application to use auth cookie
Sure you can.
You can create your own custom ApplicationUser (IdentityUser) and also create your own UserStore that implements the IUserStore interface.
Just check out the default ApplicationUserManager in the first line of the Create function you will see that ApplicationManager get constructed with a new UserStore. There you can plug in your custom User & UserStore.
Here is some good info.
http://www.asp.net/identity/overview/extensibility/overview-of-custom-storage-providers-for-aspnet-identity
I believe you should be able to use the old FormsAuthentication module in MVC5 application.
http://joeylicc.wordpress.com/2013/07/15/forms-authentication-in-asp-net-mvc/
Just make sure to redirect unauthorized requirest to your original login page.
In my ASP.Net MVC web application any unauthenticated and anonymous user can type a URL ( for example localhost:16621/Controller/Index/1 ) and access that page. How can I prevent from this???
In ASP.NET MVC, use the AuthorizeAttribute. But you'll probably need a user system that uses a database or authenticates against Google/Facebook using Oauth.
Take a look at the [Authorize] attribute.
You can find more details here and here.
In ASP.Net MVC, are the Forms Authentication and Membership Provider tightly coupled?
The Membership provider model is very different than the existing user validation services that I already have that I need to integrate with. I would like to write my own class to manage users, but still use the built in forms authentication and forms cookie to allow a logged-in user to access authenticated sections of the website.
Can I just delete the reference to the MemberShipProvider from web.config and call my own custom class from the controller I use to validate users? Will Forms Authentication still work?
You can either create a custom membership provider as #negadro mentioned or just call the SetAuthCookie after your custom validation.
//your custom validation logic here
FormsAuthentication.SetAuthCookie(userName, rememberMe);
You can create custom membership provider. This answer will help you , i think. How do I create a custom membership provider for ASP.NET MVC 2
I have an ASP MVC app that uses it's own custom authentication mechanism. However there is only one Action in one controller that I need to secure using Basic Authentication.
The idea is when the URL for this particular action is hit, the browser pops up the basic authentication dialog and then I need to have the username and password IN the action itself.
Any suggestions?
This is the answer which works:
ASP.NET MVC - HTTP Authentication Prompt