I am creating a new website, and it's already online, but I want to block access to everyone! And just let my client use it to check the development process everyday, so he don't need to download everything and set up on his computer..
I was wondering about using ASP Identity, is there any simple "hack" to achieve this?
Or my only way is the following:
- Add the Register Page to the WebSite
- Register an account with Administrator role
- Delete Register Page of the WebSite
- Use always the same account to check the page
Waiting for an answer, how to simply and easily achieve this?
EDIT: Maybe there is a way to create a default username (that in this case will be my Administrator?)
Thank you! Thank you very much!
As the user @trailmax suggested I was not choosing the best place to insert default users for Identity, since I was inserting the users each time the constructor of the context was called.
After analysis of course that's not a good option, because every time I access my DbSets I use the context constructor, triggering additional sql queries to Roles and Users DbSets, without need (because I only need that query on the startup to insert the users if they don't exist).
So.. since my web-hosting plan don't allow any Update Migrations neither Seed Methods to be runnable from Package Manager Console (because it always reference the 'master' database which I don't have permissions), I figured out this solution:
1) I create all my tables running a sql script on my remote mssql database (to get the generated SQL Script from my contexts and models, I type the following command in Package Manager Console:
2) Then I need to set Database Initializer to null, so EF doesn't try to drop/create a Database and finnaly I just invoke a method on my Context Class from my Global.asax in the method Application_Start:
3) And here is my method, that is only called on Application Startup (I am almost sure about it, at least I hope so, I wanna save CPU Clocks!)
I hope this helps someone out there, and thank you @trailmax !
How secure do you need this to be? You could go about it in another fashion, by restricting by IP.
Option 1 - Only allow specific IPs to your site
I'd recommend blocking all access to the site in your web.config and only whitelist the IP(s) that you and the client would be connecting from - it'll save you time, and it would ensure that you're only getting connections from IPs you trust.
Modify the appropriate web.config
Add as many
<add>
directives as neededOption 2 - add basic authentication to web.config
This is not a permanent solution. Look into other authentication methods for long term.
So I manage to this with a specific DbContext that creates my default user if he doesn't exist on the Database.
Here is the follow up code:
Then I needed to specify the config class for the Identity creating this class on App_Start:
And last I had to add the following in Web.config:
I hope it helps someone out there ;)
Good luck!