Any simple way of using forms authentification based on user roles? - c#

I want to make a application for customers.
It should contain :
1.Login page
2.Page for simple users
3.Page for administrators
I've found on google a lot of examples but 90% of examples have 20+ pages with some a lot of advanced things and I can't handle reading everything from them.
I just want to make a simple login page , and use 'user role' for the page where user is redirected and 'administrator role' for the page where administrator is redirected.
When I'll finish the page I will public it on a webhosting , and the main problem is that I need user roles,pass,name in a database in asp not on a website .
Is there any easy example to follow ?
Thanks

For a long time I had the same problem - most examples have you create the default schema which has a crazy number of tables.
The simplest example I have found is:
How to: Implement Simple Forms Authentication
It doesn't deal with the persistence layer at all, so it is really simple to adapt as you see fit.

Related

Asp.net works on mobile device

I asked to get clarify, I have an asp.net site it works great.
Site Contains many pages ,what I aim to do, is to make this page works on mobile device.
The Real problem it, my page contains many and many controls, So there is messy in the page .
First I want to know, how can I make page on asp.net works on mobile device?
Second ,Is it should to create a new one to get few of controls of the main page , because on the mobile page I need only few of the original .
Update:-
my site is responsive
But I have a specific page which have a lot of controls and it looks messy in appearing on mobile , So I need to create a new page similar to this page with fewer controls appears only when user use mobile not web browser.
Sorry for bad English, or being not organized.
Browser sniffing is not reliable. You should look to redesigning your site as RWD (Responsive Web Design). Use Nuget to bring in Twitter Bootstrap and start from there.
Here's an example using Web Forms (MVC would be similar):
http://www.mytecbits.com/microsoft/dot-net/bootstrap-3-0-0-with-asp-net-web-forms

Adding a re-usable 'box' to my asp.net web app

I'm building a basic web application in ASP.NET 4.0 with C# in Visual Studio 2010 Pro. I'm still very new to C#, and am used to Delphi coding. My website already has registration/login, and although I use some asp.net controls, a majority of my pages are dynamically loaded from my SQL database and I manually compile the HTML code from C# and insert it into the document.
Now what I would like to do is implement a poll - or a vote box - an 'object' which can be re-used in different pages. My website's master page already has a permanent left panel which has things which show on every page. One of these will be a small box with a vote of a few questions.
All I need to know is how do I begin to build an independent plugin control for a web page like this? I don't necessarily mean a separate DLL or anything, my existing one can handle everything. But I'd like to re-use the same little voting box in different pages too. So I'm assuming this will be considered a separate page, in a way, which is probably about 120 pixels wide by 80 high. Each vote will be limited to either login account or ip address (which I already have access to). So this solution must interact with the existing asp.net application.
So how do I begin the 'backbone' of such a plugin which can be re-used in multiple pages? I do not plan on distributing this plugin, and I don't even know if this is the correct term for what I need. Just a 'box' which can be 're-used' on multiple pages - which must interact with the asp.net app.
To better explain what I mean, imagine how Facebook has the plugin where you can embed some general info about likes and such. I'd like to make my own box like this - and even be able to embed it in other websites.
It sounds like you just need to make the poll into a user control. The documentation should get you started with them. A control can access everything an ASP.NET page can when it comes to the login information. It won't handle embedding into other pages though – embeddable active content that authenticates against your site is a nontrivial problem.
As I said in the comment, if most of your HTML is creates as a blob that's opaque to ASP.NET, it will probably be nontrivial to insert a user control into the middle of it.

Multiple page form in asp.net 3.5

I am trying to design a multiple page web form to collect information from the users. Users can quit at any time and then come back later on the page where they left, I send an email to users containing a link back to their application when they start application process. I am wondering if I can do this with asp:wizard? Does anyone know whether I can use asp:wizard to start from a page where user has left along lets assume 3rd page with their filled data and also when they click back, they should be taken to the prev. page i.e. 2nd page.
I think this is not a good approach. There must be some alternative, that you must try. Nut If this is your requirement, then you might face issues like this
You need to maintain a database of the anonymous users or the users that are using the wizard. Result waste of database sapce.
How would you define that the returning user is the same genuine user , not some bot or hacker. As this might leads make data public. For example you are Akshay , you filled up to wiz#2 and quit. Now next day you want to complete the form. How the system will know u r Akshay Kumar not Sunil Shetty. Also if some Jhonny Lever come and might take a hit and trial on Akshay , then he will get you.
So take a deep thought on the issue and discuss with the seniors regarding the alternatives, also there are lots of SO Guru, which will definitely suggest you some good way out.
I am not using Wizard anymore, but it is possible to go back to any step of the form wizard by using Wizard.MoveTo method. see here

How to show the list of recently visited web pages as chrome does

I would like to display the list of recently accessed/visited web pages just as google chrome shows. I want to achieve this using C# and asp.net.
I am working on a site where the user can see the list of pages that they have visited, I tried using iframe but that does not work as per expectation. I am looking for a clean and intuitive interface something like google chrome.
I would like to provide a thumbnail view of the recently visited pages.
To keep my question simple, I want to display a list of urls as thumbnails, just as chrome does
Note that Chrome can do it easy, as they get to render the page and can take a bitmap snapshot of it easily to show for the thumbnails. (These are not live websites in there)
If you want to do the same thing, you have to render the website offscreen and take a snapshot to show to the user.
If you want to actually show a live website - now that's another story. There are a lot of sites that don't like being shown in the context of another website (for whatever reasons - security, marketing and so on) and will employ any tricks (including legal) to make sure this does not happen.
Pages only visited within your own app?
There are several components that will alow for that using their api. For example:
http://www.tonec.com/products/wssh/index.html
You can just take a snapshot after the DOM for tha page is completely generated and save the output using the tool on peruser basis.
Now, if you want something more generic that works for any web site, you'd probably want to go with a web browser plugin.
Here would be a possible solution, although I've not tried it personally:
Keep a record of all the pages that a user visits (e.g. in a database)
When the user visits a landing page on your site, you could call the WebBrowser.DrawToBitmap function to render a bitmap of each page they have visited recently.
Please note: this is just a theory, I'm not saying it will work! ;)
This link might help you get started:
http://pietschsoft.com/post/2008/07/c-generate-webpage-thumbmail-screenshot-image.aspx

ASP.NET security

I'm currently converting our company database application from VB to ASP.NET. This is pretty much my first ASP.NET application, and I had a question about security. I would like some users to have the ability to add or edit data, while other users can only view and print reports. Now, as I understand it, in ASP.NET, I can use form-based authentication to restrict access to certain pages, but what I really would like to do is use the same web page for not only viewing the data, but also editing it (using a grid view). I don't see how I can do that using forms-based authentication without having separate (but similar) web pages in different folders, each with it's own level of security.
I guess I could always use the same web page, then check the users roles to determine if I should enable the 'edit' button or not. Is that a good (and common) programming practice?
Thanks
Checking the role membership is an accepted way of doing it. Do not however just check when you display the button, check during the response to the event it triggers as well, just in case someone tries to bypass event validation.
User.IsInRole() is what you need. As mentioned, check this at each step - users can fake any kind of HTTP response, so every server-side method needs security checks.
Don't just check whether to enable or or not... You must also check it when the edit button is clicked.
I would implement my own custom RoleProvider (MSDN Article). And then have different roles that describe the different access levels on your application, and like blowdart said check when buttons, panels are being diplayed whether the user has access or not to that resource.
Can I recommend using monitoring SQL Profiler (or similar) when you are testing the page if you are using a database? You'll be surprised the amount of calls the db gets for a seemingly trivial page load.
Also, please check security trimmings in ASP.NET. Worth having a look.
Cheers.

Categories