0

IIS and Windows Integrated Security

by dimitrovski 10. November 2008 12:43

I had a real head scratching problem today. While working on one of the internal web applications, I was trying to get the identity of the visitor so that I know what roles to assign. But User.Identity.Name kept returning a blank string. I was checking and double checking the settings in IIS to see if the “Integrated Windows authentication” is enabled and every time I’d see that it is indeed on I would come up with some obscure idea why it is not enabled (even though it was). I was misdirected by the fact that on my local IIS instance I did not encounter that problem. So the reasoning was that “there must be something wrong with the settings on the server”.

The problem later on turned out to be with the web.config. I had accidentally removed the deny directive for non-authenticated users (in the 2nd line bellow). Without that line the Windows integrated security would not kick in and hence the User.Identity.IsAuthenticated would be false and User.Identity.Name would be blank. Putting back that line solved the problem.

<authorization>
   <deny users="?"/>
   <allow users="*"/>
</authorization>

Hopefully in the future I’ll be more careful with the web.config edits :)

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

ASP.NET

0

Handling Session_End events

by dimitrovski 3. November 2008 16:52

After adding error logging features on one of the legacy applications at work the Event Viewer started recording few unhandled exceptions. This was one them

Exception information:
    Exception type: HttpException
    Exception message: Request is not available in this context

The stack trace pointed to Global.Session_End(Object sender, EventArgs e) as the source of the event.

In the Global.asax file, the Session_End event was handled like this

   1: Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
   2:     ' Fires when the session ends
   3:  
   4:     Request.Cookies.Clear()
   5: End Sub

The problem was not evident at first (to me at least) but after some googling around I found out that “Session_End is fired internally by the server, based on an internal timer. Thus, there is no HttpRequest associted when that happens.”  So this meant that the the cookies can not be cleared from the request because there is no request associated with this event.

This link here has a lot more information on the Session State and the different possible modes of handling session state in ASP.NET.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

ASP.NET

0

Four heartwarming lines of code

by dimitrovski 24. October 2008 19:21

So far I am quite happy with what BlogEngine provides for me. However there is one small annoying issue that raises the hair on my head each time I notice it. The thing is that when entering comments, in the country selection box if I wanted to choose my country, I have to select Macedonia (FYROM). The thing is the term FYROM is very derogatory for me and all the Macedonians (at least those that I know). I am not going to go into details about the whole issue because this blog is not the place for it. But if you want to know more details check this page on Wikipedia .

Therefore I decided that at least on my blog I have to do something about it. At first I thought that there would be some kind of an xml file with all the countries, but after some poking around the code base, I realized that for this purpose the RegionInfo class is used to populate the combobox with the countries. More...

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Off topic

1

Cleaning DBNull values in a DataTable

by dimitrovski 24. October 2008 16:18

Have you ever been “greeted” with a message like this?

Server Error in ‘/’ Application.

Operator is not valid for type 'DBNull' and string “”

This is what happens when you work on an ASP.NET application and you try to do some string operation on a field that you expect it to be a string while in fact it is a DBNull. Since DBNull does not support the String methods in .NET the application crashes. I’ve had this sort of problem also when working with WinForms applications but I do not remember what were the error messages in that case. (I am pretty sure that there is a good reason for the distinction between DBNull and Nothing (null), but from my ‘too lazy too dig deeper into it’ perspective it seems like it is not necessary.)

The first thing one can do to prevent problems like this one is to write the queries that retrieve the data in such a way that they do not return null values. For example

SELECT ISNULL(MiddleName, '') as MiddleName
FROM Person

With this simplified query for each row where the MiddleName is null, the database will give us an empty string instead. Quite simple but unfortunately sometimes we do not have access to the query and we are stuck with a result set that contains null values. In that case one way to deal with it is to always check for a DBNull (for the fields that you know that can contain null values) before you want to perform some operation with the database value. For example More...

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

ADO.NET

0

Blog Entry Using Windows Live Writer

by dimitrovski 24. October 2008 11:57

I just downloaded the beta version of Windows Live Writer. After the install there was a simple wizard style configuration, and after providing a blog type address, entering an url here and a password there, in less then 5 minutes everything seems like it’s working fine. I have a live preview of the blog post that I like a lot and I guess there are some other features that will come in handy (for now I have the “format code” extension or something like that in mind)

I was also asked to set up the images folder so maybe it is not a bad idea to test how that works.

anewday

Edit: It looks like I have to be careful when setting the width of the images. If the width is greater then the width of the ‘main-blog’ container (580px with my theme) then the sidebar is pushed down at the bottom.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

General

Powered by BlogEngine.NET 1.4.5.0
Original Design by Laptop Geek, Adapted by onesoft