Prompting a user when activating a SharePoint feature through the site - c#

I would like to know if there is a way to prompt the user when activating/deactivating a feature within SharePoint.
The background behind this is that I have a SharePoint solution that deploys several configuration files that are modified by the user when deployed to the site. I would like to either allow the user to decide whether or not to overwrite the files when activating or deactivating a feature.
Thanks guys!

Do you need this to work on ANY feature that is activated in your site, or just on features that are developed by you? If this is the latter case, you can add an event handler (SPFeatureReceiver) to your feature and catch the feature activated event.
EDIT: As per #Muhimbi's comment I finally understood the question - you want to allow user edit some properties and only then to activate the feature. In this case, I would suggest to define the feature as "hidden", so it does not show up in "web features" and "site features" list. Then create a custom page for "administration" of this feature, which would allow the user to override the settings in question etc. Then, register this administration page with SharePoint (again, deployed as a feature, these two features may be stapled together). Quote a good article about it can be found here: http://www.tonstegeman.com/Blog/Lists/Posts/Post.aspx?ID=13
EDIT2: found a similar article here on SO: SharePoint Feature Activation Form
One of the responses gives a good point - "The problem is, you don't always know where your feature activation code is going to run. If you turn on the feature using stsadm, it will execute in stsadm.exe, not the web process."

Related

Sharepoint 2016 - One master page for every site

I am currently working on a SharePoint 2016 system. We are upgrading from a SharePoint 2010 where we had one master page. Our goal is to have a single master page for every site in our environment. We can't use publishing to do this since we need site templates. So that route is out.
If possible I am looking for a way to catch, perhaps via a feature, when the masterpage is loading and redirect it to use custom master page. I haven't been able to find an event that I can use to do this.
Note: This is an onsite installation and not office 365.
Any help would be much appreciated.
After a long while we finally settled on a solution. We created two features. One for the site collection and one for SharePoint Central Administration.
The site collection feature forces all children sites to update their master page to a specific one. It also adds event listeners for new sites so that they also point to the correct master page.
The web app feature is used as a "switch". When it gets enabled it activates the site collection feature. When it gets disabled then it deactivates the site collection feature.
It's not a super great solution. However I thought I might post it here for those that are unable to move away from SharePoint (like us).

Internet explorer 8 issues with design

I'm working on a project a tool to track holidays and there are some parts of this application (report administration), the role "user" should not see. So far that works without problems, but somehow the representation of the parts that a "user" should not see look terrible:
The permission who should see something on the page is controlled in the Web.sitemap
<siteMapNode title="Vacation" roles="Administrator,Location Business Leader,Business Leader,Department Leader" description="All employees with vacation" url="~/EmployeeView/UserVacationGrid.aspx" />
If someone had the same problem and, could you give me some good tips or a solution how to fix this I would really appreciate it!
The problem is that whatever you are hiding (either client side or server side) is not encapsulating all of the controls associated. So for example, if you were using an ASP.NET menu, then you could hide a menu option server side with the following code:
switch (UserRole) {
case "Administrator":
Menu1.Items.Item(0).Enabled = false;
break;
}
These controls will make sure to collapse all the associated HTML with that option. If however you are using your own controls, or hiding things client side you need to make sure to hide the entire container (i.e. <div>) containing the control. A good way to do this is with jQuery:
$("#divVacationControl").hide();
Your best bet at figuring out which controls in IE8 are not being hidden and leaving that undesirable look is to use the IE developer toolbar. You can access it via F12 button, or Tools -> Developer Tools It can also be downloaded from here: http://www.microsoft.com/en-us/download/details.aspx?id=18359
Once open use the 'Select Element by Click' function to inspect the non-hidden elements and inspect the DOM. You can then find the culprit not being hidden and check your logic.
The last method if it only happen in a certain browser is to set its compatibility mode. Not saying this is the best way but it's an option. You can read how to do this in a blog post of mine below; just use IE7 or whatever worked for you. I would not recommend this approach as a long term solution unless this is a corporate intranet app that you have total control over the environment.
Specifying Document Compatibility Modes for ASP.NET Intranet Sites using IE8

How to get user input during windows installer for WinForms application?

I have a call tracking application that I've built and now I need to create a Windows Installer that bundles the .NET Framework 4.0 with the installer and also allows the user to enter a authentication id, when installing the application.
Then be able to get the value they entered to setup the application for their specific location, by setting an application setting, within the WinForms application.
If the installer can write the authentication id to the registry, I could grab it from there in my application, on startup.
Just not sure which installer to use that would make this as painless as possible.
All of the things in your question can be done by using Visual Studio Setup projects. But bit painful procedure. Do google search for finding resources about writing to registry and grabbing values at the start-up.
There may be other tools that give these functionalities in a more user-friendly way. I know only about Visual Studio Installer.
This article explains about adding custom dialog boxes.
This is completely easily can be done using NSIS (Nullsoft Scriptable Install System). It enables script based creation of installers and it lets writing of installers, customize and add features and do whatever you want using its own set of commands. You may add any control to any page (text boxes, check boxes etc.) and add any number of custom pages and do whatever you want. It has its own compiler and the script you write can be compiled using it and be compressed usefully.
See the below post too:
Customizing an exsisting NSIS MUI2 page
The NSIS and MUI (Modern User Interface) documentation, NSIS examples on NSIS site and winamp forums will help you at everything in your way...
In Advanced Installer you can do that pretty easily, but it's costly though. Check this tutorial

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.

asp.net --> forgot password functionality

I am doing "forgotpassword functionality" in asp.net
My forgotpassword.aspx page consists of a username, security question, security answer, new password,retype password and a submit button.
When I click on the "forgotpassword" link at the previous page, it should prompt me about the security question and when I enter the answer at the security answer textbox, the control should take those two (security quesion and security answer) to the backend (database) and validate that the security answer is correct. It should reply with a boolean value. Then the next 'new password' and 'retype password' should get activated.
By means the operation of going back to database should occur when the control comes out of the security answer textbox. In windows forms we can use the 'leave' event (ex:textbox1_leave) but in web forms we don't have that.
If the solution is to use javascript, please give me the step by step process to handle the aspx (source page) and also the .cs file coding
you could use microsofts membershipprovider interfaces. you just have to implement it for your own requirements (database structure).
just have a look at http://www.asp.net/learn/security-videos/ there you can watch a lot of helpful videos for understanding and implementing membership and role providers.
it helped me also to implement my first membershipprovider.
this link might be also usefull http://weblogs.asp.net/scottgu/archive/2006/05/07/ASP.NET-2.0-Membership-and-Roles-Tutorial-Series.aspx
as soon as you have finished, you can use all microsoft login controls.
good luck
There is a forgot password component in ASP.NET 2.0 - just use that and configure it.
http://msdn.microsoft.com/en-us/library/system.web.security.sqlmembershipprovider.resetpassword.aspx
http://www.asp.net/web-forms/tutorials/security/admin/recovering-and-changing-passwords-cs

Categories