401 UNAUTHORIZED – error when developing a costume login for sharepoint

Developing sharepoint is fun its like a box of chokolads, you never know what you are goint to get (c:
I was trying to make an alternative login site because the original version is a bit boring to look at. So
after i programed all the .net fluff it was time to port it to sharepoint. and it is here fun begins.

To start with one thing to remember is that sharepoint uses a Masterpages, that’s the easy part
next where to poot your code files.  someware in the 12 hive say you,.. yes (c: and here you should stop
and read one of my other articles ,  and this one as weel.

You can still use Sharepoint designer, but i must admit visual studio is that much better(just a sidenote).
Ones you have read both artickes here is what i did.
1) make a copy of the mobile login aspx, located here(yourDrive:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS\MOBILE\mbllogin.aspx). When you remove all the mobile code it is much simpler then the one located in layputs folder.
2) Make a new folder in this directory (yourDrive:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS)
3) put your asp files and the copy of the mbllogin.aspx
3.a) rename mbllogin.aspx to  login.aspx
4) Open your webconfic and replace the default login page with yours here is a snipit
<authentication mode=”Forms”>
<forms loginUrl=”/_layouts/mjauDirectury/login.aspx” />

5) now you can costumize and merge your .net code with sharepoint (c:

NOW here you get your 401 UNAUTHORIZED and happy days,.. you are stuck.
but there is a way to remedy this. (c: here what i did.

The 401 UNAUTHORIZED error was generated, when my code was reading data  using
sharepoint SPSite, dispite of.. that my assembly was added as a trusted resource in webconfic (read 4.d ),..
damn ,.. any way here is how i solved it:

Put all your code inside one og thouse bad boys

using (SPSite sitecol = new SPSite(rootSiteUrl))
// do your stuff here

the rootSiteUrl is the url of your sharepoint site (c:
that’s the way i did it,. if you have a better one ,..
tell me (c:

and you are done,.. Happy Coding


One Response to 401 UNAUTHORIZED – error when developing a costume login for sharepoint

  1. Vida Kratt says:

    What writeup!! Very informative and easy to recognise. In search of more such comments!! Are there a facebook? I recommended it on digg. The thing that it’s missing is of color. However appreciation for these details.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: