c# - Custom method to authenticate user is ignoring one of 6 users allowed to access the page -


i wrote custom authorization method simple c#.net (vs 2008 web application project). method redirect current user friendly accessdenied page when not authorized. (using windows auth). there 6 users allowed view page. problem 1 of 6 users, user2 being redirected accessdenied page every time, when in fact authorized. have ruled out spelling , punctuation errors -that not issue.

it’s simple 2 page app, main default page , redirect accessdenied page. app works 1 user if comment out authenticatecurrentuser() method. works either way other users. why 1 user affected? had user log on computer , try – same result. moved code commented out authenticatecurrentuser () method folder on server , worked them.

should authenticating in way? i’ve seen examples seem overkill simple app. there no global.asax file - maybe should use 1 , authenticate there instead?

web.config:

<authentication mode="windows"/>     <authorization>       <allow users="domain\user1, domain\user2, domain\user3, domain\user4, domain\user5, domain\user6" />       <deny users ="*"/>      </authorization> 

code:

protected void page_load(object sender, eventargs e)         {             if (!page.ispostback)             {                               //code load gridviews             }                          authenticatecurrentuser();         } protected void authenticatecurrentuser()         {             system.security.principal.windowsidentity ident = system.security.principal.windowsidentity.getcurrent();  string struser = ident.name.substring(4);  if ( !(struser == "user2" || struser == "user4" || struser == "user1" || struser == "user3" || struser == "user5" || struser == "user6") )  {                 response.redirect("accessdenied.aspx");                  }             else             {                 label1.text = "access granted";             }         } 

update: based on comments have replaced these 2 lines of code:

    system.security.principal.windowsidentity ident =                 system.security.principal.windowsidentity.getcurrent();      string struser = ident.name.substring(4); 

with single line of code:

string struser =  environment.username; 

i not test on user2 until monday 4/27/15. report back!

follow up 4/27/15: code change made no difference. user2 still cannot access application deployed on server. went far have user2 log on local dev machine (where vs 2008 installed) , ran debugger user2. application correctly allowed user2 access home page of web app in scenario. had user2 access (remote) server files local , not allowed access home page of app. had user2 log on machine , still not access. server has exact same code files local machine. , happens user - other users can access fine, stumped why occur 1 user when others have no issue. should happen if server configuration and/or permissions issue, shouldn't it?


Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -