|
can you give me a example of method on ldapauthentication?
because i still confuse.
if i want to change my password, should i make the changepassword.aspx connected with authentication?
thanks.
|
|
|
|
|
So you're saying that you haven't written the ChangePassword method on the LdapAuthentication class, and you're surprised that you get a compiler error when you try to call a method that doesn't exist?
This StackOverflow thread[^] has several examples. You'll want the ones that use the "change password" method, not the "set password" ones.
For example:
public bool ChangePassword(string domainName, string userName, string currentPassword, string newPassword)
{
string domainAndUsername = domainName + @"\" + userName;
DirectoryEntry entry = new DirectoryEntry(_path, domainAndUsername, currentPassword);
if (entry == null) return false;
DirectorySearcher search = new DirectorySearcher(directionEntry);
search.Filter = "(SAMAccountName=" + userName + ")";
SearchResult result = search.FindOne();
if (result == null) return false;
DirectoryEntry userEntry = result.GetDirectoryEntry();
if (userEntry == null) return false;
userEntry.Invoke("ChangePassword", new object[] { currentPassword, newPassword });
userEntry.CommitChanges();
return true;
}
It might be easier to use the DirectoryServices.AccountManagement classes instead of the raw DirectoryServices classes:
public class LdapAuthentication
{
private readonly ContextType _contextType;
public LdapAuthentication(ContextType contextType)
{
_contextType = contextType;
}
public bool IsAuthenticated(string username, string password)
{
using (var context = new PrincipalContext(_contextType))
{
return context.ValidateCredentials(username, password);
}
}
public string GetGroups(string username)
{
using (var context = new PrincipalContext(_contextType))
using (var user = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, username))
{
if (user == null)
{
throw new InvalidOperationException(string.Format("User account '{0}' was not found.", username));
}
var groups = user.GetAuthorizationGroups();
return string.Join("|", groups.Select(g => g.Name));
}
}
public bool ChangePassword(string username, string currentPassword, string newPassword)
{
using (var context = new PrincipalContext(_contextType))
using (var user = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, username))
{
if (user == null)
{
throw new InvalidOperationException(string.Format("User account '{0}' was not found.", username));
}
try
{
user.ChangePassword(currentPassword, newPassword);
return true;
}
catch (PasswordException)
{
return false;
}
}
}
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thank your for give me sample,
I will do it next, because i try with another method. And some problem come back. I will try with your code, but i want to finish this first.
i've make changepassword1.cs and i make changepassword.aspx, but the error say the current password and newpassword not exist. i try to convert textbox to string like this:
string CP = ((TextBox)ChangeUserPassword.FindControl("CurrentPassword1")).Text;
but when i run it,
System.Web.HttpException: ChangeUserPassword: ChangePasswordTemplate does not contain an IEditableTextControl with ID CurrentPassword for the current password
how can i resolve this sir? Thanks before
|
|
|
|
|
Look at your ChangePassword.aspx code - do you have a textbox with the ID "CurrentPassword1 "?
Based on the code in your original message, you don't. The textbox is called "txtPassword1 ".
The ID you pass to the FindControl method needs to match the ID of the control in the markup.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
ok sorry for that,
i tried to use same ID, but i can't get the value also
now, i change the method,
i use hmtl form in my webapp
but i found some error again in invoke.
the error says:
Unknown name. (Exception from HRESULT: 0x80020006 (DISP_E_UNKNOWNNAME))
in line 31(red code):
Line 29: if (result != null)
Line 30: {
Line 31: user.Invoke("ChangeUserPassword", new object[] { OldPassword, NewUPassword });
Line 32: user.Properties["LockOutTime"].Value = 0; //unlock account
Line 33: user.CommitChanges();
Stack Trace:
[COMException (0x80020006): Unknown name. (Exception from HRESULT: 0x80020006 (DISP_E_UNKNOWNNAME))]
System.DirectoryServices.DirectoryEntry.Invoke(String methodName, Object[] args) +119
FormsAuthAd.ChangePasswordPSI.ChangePass(HttpSessionState Session, String OldPassword, String NewUPassword) in C:\Users\Desktop\Documents\Visual Studio 2010\Projects\FormsAuthAd12\FormsAuthAd\ChangePasswordPSI.cs:31
[Exception]
FormsAuthAd.ChangePasswordPSI.ChangePass(HttpSessionState Session, String OldPassword, String NewUPassword) in C:\Users\Desktop\Documents\Visual Studio 2010\Projects\FormsAuthAd12\FormsAuthAd\ChangePasswordPSI.cs:44
ASP.webform2_aspx.ChangeMe_Click(Object sender, EventArgs e) in c:\Users\Desktop\Documents\Visual Studio 2010\Projects\FormsAuthAd12\FormsAuthAd\WebForm2.aspx:56
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9692746
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +12
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +15
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3562
Now, i still confuse with throw ex;
why i can't use it?
|
|
|
|
|
Look at your code, and then look at the sample I posted.
Your code:
user.Invoke("ChangeUserPassword", new object[] { OldPassword, NewUPassword });
The sample I posted:
userEntry.Invoke("ChangePassword", new object[] { currentPassword, newPassword });
Can you spot the difference?
The method is called ChangePassword , NOT ChangeUserPassword . That's why you're getting an exception telling you that the method you've tried to invoke is unknown.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi friends,
I need help to implement functionality of MULTIPLE.OPERATIONS which is there in excel into .net.
|
|
|
|
|
Do you have a question?
Raghavendra.Kodimala wrote: MULTIPLE.OPERATIONS Why is this all CAPITALS and why is there a period in it?
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
This is functionality exist in tools menu in libreoffice. We can apply on set of fields. Any one who uses excel, can understand what am i asking
|
|
|
|
|
Raghavendra.Kodimala wrote: This is functionality exist in tools menu in libreoffice 1. You posted in the ASP.Net forum.
2. You then mentioned Excel.
3. Now you are mentioning Libre Office.
Can you see why this is confusing?
Raghavendra.Kodimala wrote: Any one who uses excel, I've used every version since 1995 and have no idea what you are asking. Rather than be rude, can you ask a clear question?
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
|
I understood the what if analysis and concept of Multiple operations. But my exact requirement is i want to write a function with few parameters. In that first parameter is need to capture formula assigned to a variable. How can we write that?
|
|
|
|
|
This is the ASP.NET forum and it is far from clear what your problem is. Where and how do you plan to create this code? And indeed, what programming language you are talking about?
|
|
|
|
|
My problem is I am working on a new ASP.NET application where existing application is libreoffice. (Since it's also spread sheet, I am using term excel some times). In this libreoffice, I have encountered a function in a formula called MULTIPLE.OPERATIONS. I have studied about this function. It is not exactly a function, but it comes under what if analysis. This is in tools menu (libreoffice). I need to write a function in .net which behaves as MULTIPLE.OPERATIONS. There i got stucked and asking for help.
I am sorry if anybody takes rude or rash behavior from my written content.
|
|
|
|
|
Raghavendra.Kodimala wrote: I need to write a function in .net which behaves as MULTIPLE.OPERATIONS. Then you need to explain what this function is supposed to do, and exactly where you are stuck. You also need to explain how and where this fits into an ASP.NET application.
|
|
|
|
|
I already given explanation about this method. Again am explaining. This method consists three parameters. First parameter takes formula assigned to a variable. Second parameter takes the variable which need to be replaced in captured formula(first parameter). This function replaces second parameter in formula with third parameter which is also a variable. If second parameter not found in the captured formula, then function searches for second parameter variable in all variables formulas in the captured formula until it finds the second parameter variable. Then replaces with third parameter.
|
|
|
|
|
Hi Friends. I have done my project in asp.net with using webmethod concepts. I deployed it in live server. Clients are using windows 8 with IE 11/9. When users used my projects then IE version are changed to IE7. webmethod and json does not support IE 7/8. but when this page open then its automatically IE version changed and display 'JSON object' error. I tried to changed IE default version 9.but its automatically changed IE 7/8. how to change IE default version 9. what is the solution for my problem? Give me your suggestions.
|
|
|
|
|
It sounds like your headers are sent to IE7 compatibility.
Check the template page (your index.html/aspx/whatever) and make sure that the compatibility header is set correctly. For instance, for IE 9:
<head>
...
<meta http-equiv="X-UA-Compatible" content="IE=9" />
...
</head>
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli
|
|
|
|
|
Hi,
I also use this meta header name. But no use.
|
|
|
|
|
You did not say what the problem is !
|
|
|
|
|
Hi,
My problem is IE default version are automatically changed IE Edge to IE 7. But I want IE default version 9. How to changed default version of IE 9?
|
|
|
|
|
CAn you post your Meta tags.
|
|
|
|
|
|
You need to check few things here. If your application does not set to IE7 deliberately then why would browsers change to IE7, which means you dont have to set the compatibility meta tag at all.
It raises the second question which is by setting the meta tag to IE9 why wouldn't browers obey it.
My answer to the first question is, can you please check that your application doesn't alter browser's default beahviour deliberately.
Answer to the second question is that check your web.config and make sure that the correct meta tag is passed to the pages. Also check the 'view source' HTML in the browser rather than taking it from your source code.
Hope this helps.
|
|
|
|
|
I'm new to ASP, but not c#.
The fileupload control seems to be different than the rest of my controls, I cannot seem to link it to my c# code.
Do I need to create an event listener for it? Or a background worker process thread to monitor something from it?
I'm sure this is caused by me not understanding how the html and c# code work. How can I communicate between the fileupload control and my c sharp code in the background? I tried to put a javascript function into the head portion but it does not appear to be called and when I put a break point in there to test it, it does not hit the break point.
Thanks
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="True"
CodeBehind="Default.aspx.cs" Inherits="exchangePictureUpdater.exchangePictureUpdater" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<script src="jquery-2.2.4.js"></script>
<script>
function loadimage() {
alert($("#thefile").prop('files'));
}
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#imgBox')
.attr('src', e.target.result)
<%--.width(150)
.height(200); --%>
$("#<%=tbxPictureHeight.ClientID %>").val("");
$("#<%=tbxPictureWidth.ClientID %>").val("");
$("#<%=tbxPictureFileSize.ClientID %>").val("");
$('#imgBox').on('load', function () {
var height = this.naturalHeight,
width = this.naturalWidth;
$("#<%=tbxPictureHeight.ClientID %>").val(height);
$("#<%=tbxPictureWidth.ClientID %>").val(width);
var imgpath = document.getElementById('theFile');
//if (!imgpath.value==""){
//var img=imgpath.files[0].size;
//var imgsize=img/1024;
//alert(imgsize);
//$("#<%=tbxPictureFileSize.ClientID %>").val(imgsize);
});
};
reader.readAsDataURL(input.files[0]);
}
}
//function btnAddReplace_Click() {
// alert($("#imgBox").prop('src'));
//}
</script>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:Button ID="btnResolvePin" runat="server" Height="29px" Text="Resolve Pin" Width="160px" OnClick="btnResolvePin_Click" />
<asp:TextBox ID="tbxPinName" runat="server"></asp:TextBox>
<asp:DropDownList ID="ddlDomains" runat="server">
<asp:ListItem Value="1"></asp:ListItem>
<asp:ListItem Value="2"></asp:ListItem>
<asp:ListItem Value="3"></asp:ListItem>
<asp:ListItem Value="4"></asp:ListItem>
<asp:ListItem Value="5"></asp:ListItem>
<asp:ListItem Value="6"></asp:ListItem>
<asp:ListItem Value="7"></asp:ListItem>
<asp:ListItem Value="8"></asp:ListItem>
</asp:DropDownList>
<br />
<asp:Label ID="lblUserResolvedName" runat="server" Text="User Resolved Name"></asp:Label>
<asp:TextBox ID="tbxUserName" runat="server" ReadOnly="True" Width="354px"></asp:TextBox>
<asp:Button ID="btnTest" runat="server" Height="29px" OnClick="btnTest_Click" Text="Test" />
<br />
<br />
<asp:Label ID="lblBrowseForPicture" runat="server" Text="Browse For Picture"></asp:Label>
<asp:Label ID="lblPictureHeight" runat="server" Text="Picture Height"></asp:Label>
<asp:Label ID="lblPictureWidth" runat="server" Text="Picture Width"></asp:Label>
<asp:Label ID="lblPictureFileSize" runat="server" Text="File Size"></asp:Label>
<br />
<asp:FileUpload ID="thefile" runat="server" onchange="readURL(this);" itemid="thefile" value="thefile" Width="347px" />
<asp:TextBox ID="tbxPictureHeight" runat="server" ReadOnly="True" Width="70px"></asp:TextBox>
<asp:TextBox ID="tbxPictureWidth" runat="server" ReadOnly="True" Width="70px"></asp:TextBox>
<asp:TextBox ID="tbxPictureFileSize" runat="server" ReadOnly="True" Width="70px"></asp:TextBox>
<asp:Label ID="lblPictureFileSizeInKBs" runat="server" Text="KB's"></asp:Label>
<br />
<br />
<asp:Button ID="btnViewPicture" runat="server" Height="29px" OnClick="btnViewPicture_Click" Text="View Picture" Width="160px" />
<br />
<br />
<asp:Button ID="aspbtnAddReplace" runat="server" Height="29px" OnClick="btnAddReplace_Click" text="Add/Replace Picture" Width="160px" />
<br />
<br />
<asp:Button ID="btnDelete" runat="server" Height="29px" OnClick="btnDelete_Click" Text="Delete Picture" Width="160px" />
<br />
<br />
<asp:Button ID="btnSavePicture" runat="server" Height="29px" OnClick="btnSavePicture_Click" Text="Save Picture" Width="160px" />
<br />
<br />
<asp:Button ID="btnClearPicture" runat="server" Height="29px" OnClick="btnClearPicture_Click" Text="Clear Picture" Width="160px" />
<br />
<br />
<asp:Image ID="imgBox" runat="server" ImageUrl='<%# "data:image/jpg;base64," + Convert.ToBase64String((byte[])Eval("IMG_DATA")) %>' />
<asp:Panel ID="DialogControl" Visible="false" runat="server" style="position:absolute;width:200px;height:150px;top:200px;right:300px;border:thick;z-index:100" BackColor="Red" BorderColor="Black" BorderStyle="Solid" BorderWidth="5px">
<asp:Literal ID="DialogContent" runat="server"></asp:Literal><br />
<asp:Panel id="buttonpanel" runat="server" style="text-align: center; position:relative;" Height="100%" Width="100%" BackColor="Red" >
<asp:Button ID="DialogOKButton" runat="server" Text="OK" OnClick="DialogOKButton_Click" style="text-align: center; position: absolute; bottom:0;"/>
</asp:Panel>
</asp:Panel>
</asp:Content>
|
|
|
|