473,385 Members | 1,888 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Redirecting via windowd authentication

I'm trying to set up a usercontrol that I can put on specific pages to
authenticate people via their network login on our intranet. I have this in
the config file:

<authentication mode="Windows" />

<authorization>
<allow roles="ServerName\GroupName" />
<deny users="*" />
</authorization>

And then I'm using this on the control:

Dim user As WindowsPrincipal =
CType(System.Threading.Thread.CurrentPrincipal, WindowsPrincipal)
If user.IsInRole("J00000scourtnet\BailBondsDBAdmin") Then
'do nothing, ie, let them in
else server.Transfer(request.ApplicationPath & "/accessError.aspx")
End If

I'm having two problems:

1) Every time I access a page with this control, it asks for my network
username and password. Is there a way to get this automatically from my
machine or from the network automatically?

2) The redirect isn't working because the authentication is happening prior
to page load. Ie, if I'm not part of that group, it never loads the page for
me to do the redirect. My thought to solve this would be to remove the DENY
statement, which then allows me to get to the actual page, where, in theory,
I could then check the user and do the if/then. However, if I remove the
DENY statement, then the control never prompts me for my network ID, and
instead logs me as 'Iuser'.

Am I completely way off base on how I'm implementing this?

In the end, I'd like to be able to grab the network userID, see if that user
belongs to a group set up on the server, and, if so, load the page,
otherwise, redirect to the error.

For now, with my original setup, it's secure, as if you're not in the group,
you can't get in...however it's aesthetically mess (no formal error page,
just a generic 'permission denied' error in IE).

-Darrel
Nov 19 '05 #1
5 1142
Hi Darrel u are on the right way but u are missing somethings!!

Try reading through this <authorization> Element:
http://msdn.microsoft.com/library/de...ionsection.asp

To get the User logged on:- <%=User.Identity.Name%>
Are u impersonating ? If not place :-
<identity impersonate="true"/> in your Web.Config!!

Any more Questions Post it..
Enjoy!
Patrick


"darrel" wrote:
I'm trying to set up a usercontrol that I can put on specific pages to
authenticate people via their network login on our intranet. I have this in
the config file:

<authentication mode="Windows" />

<authorization>
<allow roles="ServerName\GroupName" />
<deny users="*" />
</authorization>

And then I'm using this on the control:

Dim user As WindowsPrincipal =
CType(System.Threading.Thread.CurrentPrincipal, WindowsPrincipal)
If user.IsInRole("J00000scourtnet\BailBondsDBAdmin") Then
'do nothing, ie, let them in
else server.Transfer(request.ApplicationPath & "/accessError.aspx")
End If

I'm having two problems:

1) Every time I access a page with this control, it asks for my network
username and password. Is there a way to get this automatically from my
machine or from the network automatically?

2) The redirect isn't working because the authentication is happening prior
to page load. Ie, if I'm not part of that group, it never loads the page for
me to do the redirect. My thought to solve this would be to remove the DENY
statement, which then allows me to get to the actual page, where, in theory,
I could then check the user and do the if/then. However, if I remove the
DENY statement, then the control never prompts me for my network ID, and
instead logs me as 'Iuser'.

Am I completely way off base on how I'm implementing this?

In the end, I'd like to be able to grab the network userID, see if that user
belongs to a group set up on the server, and, if so, load the page,
otherwise, redirect to the error.

For now, with my original setup, it's secure, as if you're not in the group,
you can't get in...however it's aesthetically mess (no formal error page,
just a generic 'permission denied' error in IE).

-Darrel

Nov 19 '05 #2
> To get the User logged on:- <%=User.Identity.Name%>
Are u impersonating ? If not place :-
<identity impersonate="true"/> in your Web.Config!!


Oops...actually, that is in there. Sorry for not including that in the
explanation.

-Darrel
Nov 19 '05 #3
So Darrel..
Is that working?

"Darrel" wrote:
To get the User logged on:- <%=User.Identity.Name%>
Are u impersonating ? If not place :-
<identity impersonate="true"/> in your Web.Config!!


Oops...actually, that is in there. Sorry for not including that in the
explanation.

-Darrel

Nov 19 '05 #4
> So Darrel..
Is that working?


No. Here's the code I'm using:

<authentication mode="Windows" />
<identity impersonate = "true"></identity>
<authorization>
<allow roles="BUILTIN\Administrators" />
<allow roles="J00000SCOURTNET\BailBondsDBAdmin" />
<deny users="*" />
</authorization>

Dim user As WindowsPrincipal =
CType(System.Threading.Thread.CurrentPrincipal, WindowsPrincipal)
If user.IsInRole("J00000scourtnet\BailBondsDBAdmin") Then
'do nothing
else
'redirect to error page
end if
It seems the problem is that all the authentication is happening via the
application PRIOR to me even loading my page to check for roles. My thinking
was to remove the DENY USERS part so that everyone at least gets to the ASPX
page. However, if I do that, the ASPX page no longer sees their network ID,
but rather as a generic 'iuser'

-Darrel
Nov 19 '05 #5
Darrel,

No need for anything special in web.config, no impersonate, no roles

Sub WindowsLogin()
Dim idName As String
idName = User.Identity.Name
'idName = "server\thore"
Dim lcUser As String = ""
Dim iPos As Integer
If InStr(1, idName, "\") > 0 Then
' separare server\ from server\username
iPos = InStr(1, idName, "\")
lcUser = Mid(idName, iPos + 1)

Now lcUser contains only the user name

If you also want a SqlServer Database with the user name you could use a
datareader and

dim dr as sqldatareader

If dr.read() then

response.redirect("anypage...

Kenneth P

"darrel" wrote:
So Darrel..
Is that working?


No. Here's the code I'm using:

<authentication mode="Windows" />
<identity impersonate = "true"></identity>
<authorization>
<allow roles="BUILTIN\Administrators" />
<allow roles="J00000SCOURTNET\BailBondsDBAdmin" />
<deny users="*" />
</authorization>

Dim user As WindowsPrincipal =
CType(System.Threading.Thread.CurrentPrincipal, WindowsPrincipal)
If user.IsInRole("J00000scourtnet\BailBondsDBAdmin") Then
'do nothing
else
'redirect to error page
end if
It seems the problem is that all the authentication is happening via the
application PRIOR to me even loading my page to check for roles. My thinking
was to remove the DENY USERS part so that everyone at least gets to the ASPX
page. However, if I do that, the ASPX page no longer sees their network ID,
but rather as a generic 'iuser'

-Darrel

Nov 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: TG | last post by:
Hi, I have a question concerning redirecting users who have logged in using our login page. Once they have properly filled out the form they should be redirected back to the last page they were...
1
by: Stu | last post by:
Hi All, I have an ASP.NET application to which I have implemented forms authentication to handle security. It is a relatively straight forward solution with all aspx pages residing in the root...
3
by: Vijay | last post by:
Hi, Based on the session timeout, session will be expired. Timebeing , we are manually checking in the each page, whether the session is expired or not, If so,we are redirecting to common login...
4
by: jjjooooohhnnn | last post by:
Greetings, I have encountered what appears to be a fairly common problem: RedirectFromLoginPage is not redirecting to RedirectUrl. I have tried all the advice that I could on the 'net, and...
2
by: Gary Coutts | last post by:
Hi, I am have problems redirecting from a login page. The login page is simple, with just 2 textboxes and one button. On the button click the routine below is called: I am using: Visual...
0
by: chris fellows | last post by:
I have a generic authentication web page Authentication.aspx that is used by other web pages to authenticate the user if their application session has expired after N minutes since they last logged...
1
by: Jeremy | last post by:
I have a web app that contains forms authentication to protect subdirectory called "admin" by denying anonymous users. When I request a protected resource in the admin directory I am presented with...
3
by: =?Utf-8?B?c3VyZXNocGFuZGk=?= | last post by:
Hi I am in a web site A. I want to redirect to a web site B with basic authentication. HttpWebContext and WebRespose methods are downloading a site page as html and this is not helping me. I...
0
by: embeddedbob | last post by:
Hi there, I appreciate any help on the following issue. I can't seem to find any other similar topic. (CS4, ActionScript 3.0, Flash 10) I have a SWF embedded within a page that is protected by...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.