Customizing AccessDenied.aspx in sharepoint2010
-
10 Agustus 2012 13:15
Hi,
I have a sharepoint2010 windows authentication based portal http://domain.com where in default landing site for all users is Mysite(top level site) with page home.aspx.(http://domain.com/home.aspx) I have a subsite called ClientSite which is visible to my clients only. My requirement is, when my client client1 logs in to http://domain.com, he should see only one site and that's ClientSite.(http://domain.com/clientsite should get loaded automatically when users logged in are clients). All users and clients credential are stored in AD.
Since Mysite is top level site, Client1 gets Access Denied page. However he is able to successfully login with http://domain.com/ClientSite/
Is there a way to redirect from http://domain.com to http://domain.com/clientsite only when logged in user is one of clients?
I think I can do this by customizing AccessDenied.aspx by redorecting URL as per logged in user.
Please anybody can help me on achieving this?
Semua Balasan
-
10 Agustus 2012 13:54
hi Akarkera
view bellow link:
How to use Custom Access Denied Page in SharePoint 2010?
yaşamak bir eylemdir
- Disarankan sebagai Jawaban oleh Ilker Alizade 10 Agustus 2012 13:59
-
11 Agustus 2012 4:37
Hi Ilker,
Thank you for giving a way for solution. It will be helpful for my work, But if I create custom access denied page in Visual studio, how do I get default functionalists of default access denied page? I mean how do I get code base which are already existing in default access denied? I am loosing default functionalists in my custom access denied page right! Can you please guide me on this? Sorry, I am a beginner, do not have much experience on these.
what's the solution for that?
ashwith
-
11 Agustus 2012 5:16
hi
what functionality of default access denied page you need?
yaşamak bir eylemdir
-
11 Agustus 2012 6:31I need all the default functionalists, plus an additional function which checks for type of user and if required it redirects page. Idea is to replace default access denied page with custom one.
- Diedit oleh AKarkera 11 Agustus 2012 6:58
-
11 Agustus 2012 6:35
Right now am trying it. I have created one new SP project with a application page customAccessDenied.aspx,
I have copied code from default AccessDenied (from note pad) to CustomAccessDenied.aspx and deployed. When browsing http://domain/_layouts/customaccessdenied i get error as "An unexpected error has occurred"
What to do? I have not done anything on .cs page
- Diedit oleh AKarkera 11 Agustus 2012 6:58
-
11 Agustus 2012 6:57
This what I get when I browse http://localhost/_Layouts/customaccessdenied/customAccessDenied.aspx
how do I make sign as a different user functional? How do I get logged in names?
- Diedit oleh AKarkera 11 Agustus 2012 6:58
-
11 Agustus 2012 15:32
hi
u most change page_load function as bellow code
protected void Page_Load(object sender, EventArgs e) { SPSecurity.RunWithElevatedPrivileges(delegate() { using (SPSite S = new SPSite(SPContext.Current.Site.ID)) { if (S.RootWeb.ID == SPContext.Current.Web.ID && S.OpenWeb("/ClientSite").Groups["MyClients"].ContainsCurrentUser)//this Site is root site and current User is a Client SPUtility.Redirect("http://domain.com/ClientSite", SPRedirectFlags.Trusted, HttpContext.Current); else SPUtility.Redirect(SPContext.Current.Web.Url+"/_layouts/AccessDenied.aspx", SPRedirectFlags.Trusted, HttpContext.Current); } }); }
i created a new post in my new weblog that describes answer of current problem completly. you can refer that from bellow link
Redirecting users that do not have access right to other site
yaşamak bir eylemdir
- Disarankan sebagai Jawaban oleh Ilker Alizade 11 Agustus 2012 20:40
-
13 Agustus 2012 12:31Hi,
First of all a big thanks to your valuable codes :-) I have implemented above, but ended up with error.
Error: when Feature created with 'Site' scope, Deployed solution successfully. But,
When trying to "sign in as different user" as to login as client, gives error on the page as, 'customaccessdenied.Layouts.customaccessdenied.customaccessdenied' is not allowed here because it does not extend class 'System.Web.UI.Page'.
What could be the problem? Do we need to edit aspx page of customaccessdenied.aspx??
- Diedit oleh AKarkera 13 Agustus 2012 12:58
-
13 Agustus 2012 12:58
Here is log data,
08/13/2012 18:28:52.14 w3wp.exe (0x2794) 0x25BC SharePoint Foundation Logging Correlation Data xmnv Medium Name=Request (GET:http://tseblrdc-02:5000/_layouts/accessdenied.aspx?loginasanotheruser=true&Source=http%3A%2F%2Ftseblrdc%2D02%3A5000%2FPages%2FDefault%2Easpx) e5f9e9f4-c6f0-431e-be3f-d34832b156eb
08/13/2012 18:28:52.15 w3wp.exe (0x2794) 0x25BC SharePoint Foundation Runtime tkau Unexpected System.Web.HttpException: 'customaccessdenied.Layouts.customaccessdenied.customaccessdenied' is not allowed here because it does not extend class 'System.Web.UI.Page'. at System.Web.UI.TemplateParser.ProcessError(String message) at System.Web.UI.TemplateParser.ProcessInheritsAttribute(String baseTypeName, String codeFileBaseTypeName, String src, Assembly assembly) at System.Web.UI.TemplateParser.PostProcessMainDirectiveAttributes(IDictionary parseData) e5f9e9f4-c6f0-431e-be3f-d34832b156eb
- Diedit oleh AKarkera 13 Agustus 2012 12:58
-
13 Agustus 2012 14:19
Hi,
When I included
public partial class CustomAccessDenied : LayoutsPageBase,System.Web.UI.Page
Error 1 Class 'customaccessdenied.Layouts.customaccessdenied.CustomAccessDenied' cannot have multiple base classes: 'Microsoft.SharePoint.WebControls.LayoutsPageBase' and 'System.Web.UI.Page' D:\Development\customaccessdenied\customaccessdenied\Layouts\customaccessdenied\customaccessdenied.aspx.cs 22 64 customaccessdenied
Actually it is not giving me Page option at all when i type system.web.UI.
Any idea?
- Diedit oleh AKarkera 13 Agustus 2012 14:21
-
16 Agustus 2012 5:30ModeratorHi AKarkera,
The System.Web.UI.Page is storied in the System.Web.dll assembly. So you have to add the System.Web reference in your project. Here is a screenshot about reference the System.Web.dll assembly in Visual Studio:
Thanks,
Lhan Han -
16 Agustus 2012 5:45
Hi,
No luck :-( I have included system.web.dll assembly too. Actually am using .Net framework 3.5, heard SharePoint2010 doesn't support .Net framework 4.0
What I can do?
ashwith
-
16 Agustus 2012 6:16Moderator
Hi AKarkera,
C# doesn't allow multiple inheritance class. Both LayoutsPageBase and System.Web.UI.Page are class. So you got the error, you can only let the CustomAccessDenied class inherit the LayoutsPageBase class, the LayoutsPageBase class already inherited from System.Web.UI.Page.
Thanks,
Lhan Han
- Diedit oleh Lhan HanModerator 16 Agustus 2012 6:17
-
16 Agustus 2012 6:25
Hi Lhan Han,
Yes, that's right. Am worried how do I solve this issue? :-(
ashwith
-
16 Agustus 2012 6:55Moderator
Hi AKarkera,
Here is a similar issue, please check it out:
http://social.msdn.microsoft.com/forums/en-US/sharepointdevelopment/thread/7fd6dbde-da8a-43e4-aeea-a7f9ffa5e571It may a user control issue.
Thanks,
Lhan Han -
16 Agustus 2012 7:08
hi,
ok, Can you email me your source code which worked for you?
ashwith
-
16 Agustus 2012 7:11ModeratorHi AKarkera,
I don't reproduce it, the above link is searched from internet, does it help you?
Thanks,
Lhan Han -
16 Agustus 2012 7:16
Hi,
Lhan Han,
Not yet :-(
Thanks,
ashwith
-
16 Agustus 2012 15:16
Hi,
If you have SharePoint group created for Clients, then you can write a custom web part which checks the user logged in belongs to the group. You can redirect the user programmatically to clientsite if this code returns true.
-Kranthi
-
17 Agustus 2012 4:29
Hi Kranthi,
Thanks for your suggestions, Am new to sharepoint dev. If we create web part we may need to use it in some pages right? I didnt get you how web part will help in this case.
ashwith
-
17 Agustus 2012 6:55
Hi Ashwith,
The webpart wouldn't work if the clients don't have atleast read access on the root site, which i think is your case.
I have seen another webpart also on codeplex(http://sharepointredirect.codeplex.com/) which does this, but again the user should atleast have read access to the site on which the webpart will be placed.
If giving read access is ok then this approach can work out.
-Kranthi
- Ditandai sebagai Jawaban oleh Lhan HanModerator 19 Agustus 2012 13:21