Showing posts with label ASP .Net Windows Authentication. Show all posts
Showing posts with label ASP .Net Windows Authentication. Show all posts

How to connect to SQL Server, VS TFS, etc using Windows Authentication when computer is not on Active Directory Domain

Posted on Thursday, June 25, 2009 by Nicki

I often move around between different clients, and never join their domains, simply because my machine would get cluttered with policies and logon scripts, so I've encountered this problem before.


To access a fileshare, you just map using
net use \\machinename\ipc$ /user:domain\user
This does not work for connecting to SQL Server with Windows Authentication though. I found this neat little trick to accomplish this:
runas.exe /netonly /user: "C:\Program Files\Microsoft SQL Server\90\Tools\Binn\VSShell\Common7\ide\SqlWb.exe"
This runs Management Studio as the domain user, which can then authenticate to SQL Server using Windows Authentication.

The original article can be found here

ASP .Net Windows Authentication

Posted on by Nicki

If you use Windows Authentication, and the user is not allowed to access the specific page, a nasty 401.2 Access Denied error message will be displayed to the user. What if you want to display a friendly error message?


You would think that an entry in the <customErrors> section would work? No, it does not.

To get to the solution: You have to define Application_EndRequest in Global.asax.cs that looks something like

protected void Application_EndRequest(object sender, EventArgs e)
{
HttpContext context = HttpContext.Current;
if (context.Response.Status.Substring(0,3).Equals("401"))
{
context.Response.ClearContent();
context.Response.Write("<script language="javascript">" +
"self.location='NotAllowed.aspx';</script>");
}
}

Then you create the NotAllowed.aspx page to display a nice friendly message to the user.

You can find more information here.