How To Change The Value Returned By WindowsIdentity.GetCurrent
Jan 7, 2010
I'm writing an ASP.net application and I'm working with the WindowsIdentity.GetCurrent() function. I want to know how (or if it's possible) to change what identity the ASP.net application runs as.
I eventually want to run it as an account associated with the end-user. I understand I can do this with Windows Authentication in IIS, but Windows Authentication will not work with my particular application. If I can programmatically log the user in with a AD username and password, that will be fine.
How can I set the WindowsIdentity the ASP.net application runs as without using Windows Authentication in IIS?
Update: This question has been sitting idle for a long time. I think that perhaps the framework does not allow me to do what I'm describing here.
I have an asp.net 2.0 application that is suppose to pick the Identity of the currently logged in user on a client machine and use it to setup working environment for the user. On win xp and windows server 2003 this works fine. but on moving the application to Windows Server 2008 R2 .
I have a user that when I attempt to enumerate her groups using either System.Security.Principal.WindowsIdentity.GetCurrent().Groups on user's computer or System.Web.HttpContext.Current.Request.LogonUserIdentity.Groups on the IIS server, I get a list of their old groups, not their new. I have checked the DC that they authenticate to and the ASP.NET page is running inside a SharePoint instance so the LogonUserIdentity most like is being provided from there Kerberos ticket. Should I be looking up the groups directly from the AD instead of relying on the WindowsIdentity or LogonUserIdentity?
Is it possible to change the format of the date returned by the calendarextender based on regional settings? Also, is it possible to tell the datetime object how the date string is formatted?
WindowsIdentity wi2 = new WindowsIdentity("test1");
test1 is in the ActiveDirectory on the DomainController
when running the code I get an IncorrectFunction error
at System.Security.Principal.WindowsIdentity.KerbS4ULogon(String upn) at System.Security.Principal.WindowsIdentity..ctor(String sUserPrincipalName, String type) at System.Security.Principal.WindowsIdentity..ctor(String sUserPrincipalName) at Hisco.Intranet.LoginForm.OnInit(EventArgs e) in F:HiscoDCSWebEventsManagerHiscoDCSDCSLoginForm.aspx.cs:line 17 at System.Web.UI.Control.InitRecursive(Control namingContainer) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
I have windows auth for the website and outside users will logon that are not in the network and I need to impersonate them to login on without offering a login form( quietly behind the scenes) with the test account. I guess what I actually need is the UserTaken pointer. Is there a way to get one without ising the LogOnUser unmanaged call? I have a UserPrincipal object also so is there way to get the token from ActiveDirectory somehow?
In our web application we provide a way for users to switch which account/credentials (Windows identity) that should be used when making requests to external services.
This "Switch user" service works like this:
The user provides the new credentials that should be used. The application performs a "login", fetch the toke and creates a new WindowsIdentity based on the token.The created identity is placed in the session. When a page is requested and an Identity is available in session, the HttpContext.Current.User is replaced with this one. Everything works as excepted when the application is hosted in IIS6. We have verified that all request to external services is made using the new identity. When we host the application in IIS7 we run into problems however. Everything works fine until we tries to access the new identity (for example by fetching the name) and we get the following exception:
[Code]....
We have no idea why this suddenly starts to happen in IIS7.
I have seen multiple posts related to my question but I was not able to resolve the issue. I am calling SP from C# class library and I need to check if returned XML is valid XML or not. When I run the SP in SQL management studio, I get XML. However, when I run the same SP from my c# code, I get null as return from SP. So I guess tried settings in design.dbml but to no avail.
Here is designer generated code. [Function(Name="dbo.RequestXML")] public ISingleResult< RequestXMLResult> RequestXML([Parameter(Name="RuleID", DbType="Int")] System.Nullable<int> ruleID) {
[Code]....
As output, I get "MyCo.DBNAme.Database.Environment.RequestXMLResult"
I am using ASP.net v2 and I have a page where the user enters a phone extension number and clicks the find button. This opens a connection to a database and brings back the name of the person who's telephone extension it is. When the user clicks find, it appears to post back but no value is returned until the user does it again ( it looks like one of those daft IsPostback problems that can have you scratching your head for weeks), but this only happens in IE, have tried it in other browsers and it returns the name first time. I have added code to handle no valid result.
so I have code like above, I need to assure a record was actually returned before trying to use it... I assumed I could test for null, but that doesn't appear to work.
I tried: if (task != null) {yada yada yada}
but if I put an ID that doesn't exist in my querystring it throws an exception 'sequence contains no elements'. I realize I can catch the exception but I want to understand how I should be checking for a returned record. The .Single method intellisense says it returns exactly one record or throws an exception if more than one is found... is it also throwing the exception when zero are found I'm not sure if the issue is my check for null or that line that calls .single itself? Now I'm guessing I'm supposed to just catch the exception on the line that's calling .Single... yes?
At the other end I am returning the following XML response:
[Code]....
I'm seeing my response.writes of A and B, so I know my data is making it to the other end and I'm getting a response back, but I can't seem to figure out how to read the response and redirect to the URL referenced in <URL>
I always received an error of: Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
I have a table of skills. In that table, are rows of data with various skill type. I need to return a list of those skills in alphabetical order, with one exception. The skills "General" can't be listed in the "G's", instead, it needs to be the last item. (Crazy, I know, but it's to discourage users from settling on a selection of "General".
This statement returns all the skills in alphabetical order, but "General" is listed right in the middle with other "G's:
SELECT SkillsID, Skill, SkillDesc FROM tSkills ORDER BY Skill
The values stored in my database are integers, 1 - 9. Each value has an associated string value that I want displayed in my GridView. Ex: 1 = "Active"; 2 = "On Hold"; etc. How would I filter the incoming data so I can display the associated String value instead of the Integers from my table?
I have a procedure that is used to look up user permissions in our custom table, There is 1 record for each user and about 20 columns for each of the permissions.
How can i take the column values and place into an array?
All the column are bit type and 1 is int. Is it possible to take the values returned and add to an ArrayList?
And then once the values are in the array, how to loop thru it and go to certain index to check the value.
I have a asp.net page that has several SqlDataSources defined that feed data into some graphs. The problem is that the graph product does not handle "no data" very well, and throws an error. I'd like this to handle the situation more gracefully-- so I need to check whether the SqlDataSource returned data or now before rendering the graph (and if not, just post a message saying "No Data" or something).
Is there an easy way to check if the data source returned data, and do this if/then without a bunch of code behind?
A customer using a ASP.NET program I have just sent them is experiencing the error below, I had personally tested the program on 4 web server IIS6, 7, and 7.5, on 4 different networks and I never got this, the customer is using IIS6 with .Net 2.0 (as required). The program uses Windows authentication which may or may not be part of the problem. I'm stuck I don't know where to start with this.
I wanted to use the ASP.NET Chart Controls, but since all of the available examples used a code-behind page reminiscent of Web Forms, I shied away from this. Then I found an example returning the Chart Control as a FileResult, and tried it out. It worked, I was happy and all was good in the world. Except that occasionally I'll get a broken link showing instead of the image it should resolve to.
Here's how I have it set up:
In the View, the code is very simple. It's just an image tag that has its src attribute set to the Controller method. I didn't realize this was possible, and thought it pretty cool:
[Code]....
In the Controller, I instantiate and build the Chart Control in its entirety, and then output it as a FileResult:
[Code]....
Yes, it's a bit long and involves, but that's what you get when programmatically building something inititally set up to be a server control. All of this works, and even when I get the output that shows a broken link, if I refresh the page, it generally fixes itself. Here's the code from the FileResult created for this purpose - it's not a Controller, but I placed it in with the Controllers just while testing:
[Code]....
I'm thinking that the reason behind the occasional broken link is related to the DataContext object, not any of the above code. It seems reasonable that if the DataContext doesn't build and return a FileResult quickly enough, perhaps because it's doing too many other things, the broken link would show because no file had been built where it was expected. I've included the code anyway, in case someone can find an issue that would cause the problems I've been encountering. Any advice would be greatly appreciated. I had this working with Flex chart components that I genericized so that they worked with MVC methods, but they were way too slow to complete rendering. It often took 3-7 seconds, which was just too long for a user to wait for their page to load. These Chart Controls are really fast and are a perfect solution - if I can get them to render consistently.
in .net 4.0 c# I am trying to figure out how to get all the Tags.TagName for a given product
First I get the Tag by the TagId they select, then I do another select on the Products table and join ProductTags to find any product that is using the specified tag.
Now I have to get all the tags associated with each returned product from the previous list.
does it reload the entire page or does it have the intelligence to only send the necessary js to update the needed parts of the page that have changed? if it does the latter that would be a god send, however im probably being dreamful. it probably returns the entire view without any regard, right? edit: answer seems to be no, everything is returned.
edit added: do you think it would be difficult to write a framework where mvc compares last html it output to the current html we want to output, and instead of sending the entire html, figure out what has changed and generate js code that will do the updating as compared to previous html? (presuming nothing was manually changed on the client using js)... maybe an idea for a codeplex project? or maybe something like this exists?