.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

How do I display a custom error message if Authorize fails

Posted By:      Posted Date: April 10, 2011    Points: 0   Category :ASP.Net


I have a page that can only be accessed by "Admins". If a user who is NOT an admin tries to access the page, I'd like to do two things:

  1. Log the error to the database
  2. Send the user to my error page but display a custom message

I don't know where to handle the error logging because there doesn't seem to be a controller for the error page (I'm using Razor. Just created an Internet Application MVC3 project in VS 2010)

I also don't know how to customize the error message.

Could someone give me some pointers on this?

View Complete Post

More Related Resource Links

How to Get Error Message from Job History if SQLAgent Job Fails

Hello, I am using "last_run_outcome" value = 0 (fail) or 1 (pass)  from sysjobsteps to identify if the job has failed. So if the job has failed, can I get the Error Message from SQL ? (which we can see in Job History). Thanks, Prabhat

Crawling fails with 404 error message, but the IIS log tell a different story

In our clean SP2010 install, crawling stops immediately, just logging a single error message:   The object was not found. ( Error from SharePoint site: HttpStatusCode NotFound The request failed with HTTP status 404: Not Found. )   Looking at the IIS log does, surprisingly, not  confirm this. Here are all the log entries related to crawling:   #Fields: date time s-ip cs-method cs-uri-stem cs-uri-query s-port cs-username c-ip cs(User-Agent) sc-status sc-substatus sc-win32-status time-taken 2010-09-01 15:20:42 GET / - 80 - Mozilla/4.0+(compatible;+MSIE+4.01;+Windows+NT;+MS+Search+6.0+Robot) 401 1 2148074254 15 2010-09-01 15:20:42 GET / - 80 0#.w|global\cre-nhk Mozilla/4.0+(compatible;+MSIE+4.01;+Windows+NT;+MS+Search+6.0+Robot) 200 0 0 46 2010-09-01 15:20:42 GET /Pages/Forside.aspx - 80 0#.w|global\cre-nhk Mozilla/4.0+(compatible;+MSIE+4.01;+Windows+NT;+MS+Search+6.0+Robot) 200 0 995 937 2010-09-01 15:20:43 GET /_vti_bin/sitedata.asmx - 80 - Mozilla/4.0+(compatible;+MSIE+4.01;+Windows+NT;+MS+Search+6.0+Robot) 401 1 2148074254 0 2010-09-01 15:20:43 GET /_vti_bin/sitedata.asmx - 80 0#.w|global\cre-nhk Mozilla/4.0+(comp

Null reference message Custom Error page

how come a Null session value that is called, doesn't get directed to the Custom Error Page?

How do i display a custom message when my ListBox is empty?


I've got a ListBox. Its ItemsSource is Data-Bound to a Dataset.

When there are entries in the Dataset, the ListBox displays them, and it doesn't look so bad.

The ListBox is big, so when its empty it looks weird on the Window.

What i want to do is to display a custom mesasge somewhere inside the listbox(maybe in the center) if there is nothing to display. But i've had no luck sofar.

How could i go about achieving this?

People Picker fails to search or resolve and return an error message.



I got an error while trying to access the people picker from some specific locations. I'm experiencing those problems ONLY in the cental administration and also there, just on a few places. For example if I try to change the authorization settings of any service application there is a different people picker pop up than, for example, if I want to change the admins of any service application. Any other people picker window outside the central administration works for me.

So it seems to me, that there are two different types of people picker windows. The one which is not working for me also appears in the metadata service application which is the reason I can't use this service as I'm not able to define an owner of a keyset.

In the error log I found the following message: "Ausnahme im Forderungsanbieter 'Alle Benutzer' beim Aufruf von 'SPClaimProvider.FillHierarchy()': Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt." It basically says: An exception occurred in 'all users' claim provider when calling 'SPClaimProvider.FillHierarchy()': The object reference was not set on a object instance. This is event-id 8307 which you can find here: http://technet.microsoft.com/en-us/library/ff535778.aspx

Access Denied Error Message from Custom Webpart



I am new to MOSS so can anyone please help me to solve this problem.


I've a list in MOSS-2007, and a group of people with Read Only Rights so they cannot change any list item. But I want to give them access to edit one column (i-e Comments) in that list.

So I created a custom web part page and put a comments text box in it. At DispForm.aspx page of list there is a link which redirects to Custom page for adding comments and I am passing Item ID in query string.

But the problem is that when anyone adds the comment on custom page an ACCESS DENIED message appears. I've even set "web.AllowUnsafeUpdates = true" but didn't work


                SPWeb web = SPContext.Current.Web;
                SPList lstTIX = web.Lists["ListName"];


Web.Lists fails without any error message

The following code is place in aspx file
 Response.Write("Publish in<br/>");





  Response.Write("Publish Start<br/>");

  StringReader objReader = new StringReader(sPublishedData);

  DataSet dsData = new DataSet();


  iReceived = dsData.Tables[0].Rows.Count;

  iPublished = 0;

  if (sUrl != "")




   Response.Write("Url " + sUrl + "<br/>");

   sUrl = sUrl.ToLower();

   sUrl = (!sUrl.StartsWith("http://") ? "http://" : "") + sUrl;

   using (SPSite site = new SPSite(sUrl))


    using (SPWe

Need help with a custom error page that shows the error message details


I know how to alter the web config to redirect to an errors page but what I need to do is have the actual offending error message print to that page. This is a special request for testing reasons, I realize the whole point of a custom error page is to provide a user friendly message when an error occurs but for testing we want to show the user the message so they can copy and paste it into a ticketing system we are using for beta testing feedback.

Should I use the global.asax instead? I am pretty new to vb.net and am not sure how to get the actual error message to display on my custom error page. Any guidance would be greatly appreciated.


Windows Update error message 84B30001 - SQL Server 2008 SP2 update fails


I am running Windows 7 Professional on a 64 bit platform and have Windows update on and selected to notify me when updates are available.  The other day, I received an error message that an update failed to install properly.  The update that failed is to update SQL Server 2008 SP2 - KB 2285068.  I have made several attempts to retry this update with the same result.  When I Googled the error message, all of the responses deal with the SQL Server 2008 SP1 update not SP2.  Couldn't find a solution to this problem - nor could I find one in the KB article - which basically explains details of SP2 and DOES give me the option to instal SP2 from here.  Don't want to take the chance and download it from here - maybe I should though.  Can usually find a solution to a Windows update error in Google - can't find one this time.

Any suggestions?

Jim Cutrara

Jim Cutrara

How to display model level custom data annotation validation error?


Hello Experts,

I am a MVC newbie & am lost in various ways validation can be implemented in my application.

I created a custom model-level data annotation validator attribute, but am unable to display its error message in the view. Basically, I have let's say 5 properties in the Entity class Job (model-level custom attribute called UniqueKeywords defined on it):

1) LoginID: value comes in the URL

2) Title: Required property level attribute defined on it

3) CatID1, CatID2, CatID3 - 3 categoryIDs - these are dropdowns in the view with same list of keywords in all 3.

I want to mandate that the values picked by the user in all 3 category dropdowns should be different.

With reference to the code pasted below, here is the explanation of what happens:

When I submit the form without specifying a title or picking anything from any of the 3 category dropdowns, the validation occurs for the property level Required attribute as well as model level uniquekeywords attribute, but the error is displayed only next to the required field "Title". I can confirm that the custom validation also works by filling in some text in the Title field & then re-posting the form...this re-displays the view, but the error message "Category cannot be duplicated" is not displayed.

Looks like I am missing s

Show custom error message inside SharePoint Business Data List web part?

I am using SharePoint 2007 Business Data List web part to show external information retrieved from my simple web service. Is there ability to show custom error message on Business Data List web part?

Inconsistent error message on Custom Workflow.


Recently on custom workflows I've been getting this error message when trying to navigate to you a custom task form on a workflow.  I had to enable logging to see it instead of "Unkown Error." 

Only Content controls are allowed directly in a content page that contains Content controls.   at System.Web.UI.FileLevelPageControlBuilder.AppendLiteralString(String text)
   at System.Web.UI.TemplateParser.ProcessLiteral()

This message only occurs randomly and if I hit refresh a few times the task form will display.  This message occurs in two custom workflows. I'll start testing the out of box workflows and see if this message comes up.

Error message "Could not locate the security token referenced by key info" with WCF custom client (V



I’m trying to develop a custom client, a console application, to connect it with a Web Service (Java Web Service) and call publics web methods with Visual Studio 2008 (.Net Framework 3.5) and WCF, but I’m getting an error message (“Could not locate the security token referenced by key info”).

I’m employing two certificates, a server certificate and a client certificate, because I have to sign and encrypt the message that I send to the Web Service. Both certificates are correctly installed in my certificate repository. In my client Web Service generated with “svcutil” tool, I’m added this line to sing and encrypt the message:


Inserting personal error message in ValidationSummary



I am creating a web form that requires a lot of validation. I use many of the validation control in asp.net already like RequiredFieldValidator and CompareValidator. 

My Problem: after my custom validation for the value entered return an error message, and I pressed enter key when the field is empty, my custom error message is overlapped by my ValidationSummary. 

Setting my custom error to visible = false on button click also does not seem to work as it requires for me to enter the value first.

This made me think, is there a way to insert my custom validation inside the ValidationSummary as an error message like for other validation control?

Thanks in advance

create user wizard login error message dont show in a message box?




i am using create user wizard and capturing other information within content template when a new user

registers. Some of the textboxes are binded to required field validators.


there is a validation control on the page and ShowMessage box is True.

If they dont complete some of the text boxes then the message box pops Up with the error message.

It does not however include information errors like "User already exists" or Email address already exists

from the create user wizard membership  UserName and Password Textboxes


is it possilbe to hook all of these up so I get one message box with all errors including membership ones?




Very Basic Question - Error message running first page


Hi Everyone,

I am running Windows 7 and I have gone into Control Panel and activated all of the IIS Functions.

The web application I am running was downloaded from the net (and has worked on other machines previously).  Once I downloaded it, I moved it into C:/inetpub/wwwroot/code/main.asp

I am a bit of a novice at this!  But I am hoping someone can point me in the right direction!


I get the following error when I try and run the web application through IE:

"An error occurred on the server when processing the URL. Please contact the system administrator. If you are the system administrator please click here to find out more about this error."

(When i click the "click here" button it just goes to the IIS site).


Appreciate any help I can get!




Custom Control Design-Time SiteMap Provider Error


Greetings - I was referred here by MSDN forums hope this is the right place -  

I have a custom control (:WebControl) that renders web.sitemap in a specific way. While it runs error free and produces the expected result, at Design-Time it complains

Error Creating Control - MyControl  The provider 'AspNetXmlSiteMapProvider' specified for the defaultProvider does not exist in the providers collection.

I have discovered that the error is cause by this line of code:

string div = string.Format("<div class='{0}' id='{1}'>{2}</div>", this.CssClass, this.ID.ToString(), EnumerateNodesRecursive(SiteMap.RootNode, level));

or more specifically, by the reference to SiteMap.RootNode - I am not clear what is missing thoough because I have configured the SiteMapProvider in web.config as this:

        <add name="AspNetXmlSiteMapProvider" 
             type="System.Web.XmlSiteMapProvider, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend