 |

|
Apologies for the shouting but this is important.
When answering a question please:
- Read the question carefully
- Understand that English isn't everyone's first language so be lenient of bad spelling and grammar
- If a question is poorly phrased then either ask for clarification, ignore it, or mark it down. Insults are not welcome
- If the question is inappropriate then click the 'vote to remove message' button
Insults, slap-downs and sarcasm aren't welcome. Let's work to help developers, not make them feel stupid.
cheers,
Chris Maunder
The Code Project Co-founder
Microsoft C++ MVP
|
|
|
|

|
For those new to message boards please try to follow a few simple rules when posting your question.- Choose the correct forum for your message. Posting a VB.NET question in the C++ forum will end in tears.
- Be specific! Don't ask "can someone send me the code to create an application that does 'X'. Pinpoint exactly what it is you need help with.
- Keep the subject line brief, but descriptive. eg "File Serialization problem"
- Keep the question as brief as possible. If you have to include code, include the smallest snippet of code you can.
- Be careful when including code that you haven't made a typo. Typing mistakes can become the focal point instead of the actual question you asked.
- Do not remove or empty a message if others have replied. Keep the thread intact and available for others to search and read. If your problem was answered then edit your message and add "[Solved]" to the subject line of the original post, and cast an approval vote to the one or several answers that really helped you.
- If you are posting source code with your question, place it inside <pre></pre> tags. We advise you also check the "Encode "<" (and other HTML) characters when pasting" checkbox before pasting anything inside the PRE block, and make sure "Use HTML in this post" check box is checked.
- Be courteous and DON'T SHOUT. Everyone here helps because they enjoy helping others, not because it's their job.
- Please do not post links to your question into an unrelated forum such as the lounge. It will be deleted. Likewise, do not post the same question in more than one forum.
- Do not be abusive, offensive, inappropriate or harass anyone on the boards. Doing so will get you kicked off and banned. Play nice.
- If you have a school or university assignment, assume that your teacher or lecturer is also reading these forums.
- No advertising or soliciting.
- We reserve the right to move your posts to a more appropriate forum or to delete anything deemed inappropriate or illegal.
cheers,
Chris Maunder
The Code Project Co-founder
Microsoft C++ MVP
|
|
|
|

|
As a part of my website, I need to diaplay a .swf file in my home page. Could anyone please tell me how to insert the .swf file in ASP.Net page
|
|
|
|
|

|
<div class="WelcomeImage"> <object type="application/x-shockwave-flash" data="~/Images/slideshow_header02.swf" width="200" height="100"> <param name="movie" value="~/Images/slideshow_header02.swf" /> </object> </div>
This is my code which is not displaying anything..should i need to do anything else..
|
|
|
|

|
Make sure you have referred right swf file(path & file name).
Make sure you have swf files in that path.
Load some other swf file & make sure it's loading. If it's loading then the problem in your swf.
thatrajaCode converters | Education Needed
No thanks, I am all stocked up. - Luc Pattyn
When you're wrestling a gorilla, you don't stop when you're tired, you stop when the gorilla is - Henry Minute
|
|
|
|

|
Hi,
I am trying to get the following code read credentials from the user class but I experiencing the following principal error -- "The name 'PrincipalProvider' does not exist in the current context".
public class BasicAuthMessageHandler : DelegatingHandler
{
bool _RequireSsl = true;
public bool RequireSsl
{
get { return _RequireSsl; }
set { _RequireSsl = value; }
}
private const string BasicAuthResponseHeader = "WWW-Authenticate";
private const string BasicAuthResponseHeaderValue = "Basic";
[Inject]
public iUser Repository { get; set; }
protected override System.Threading.Tasks.Task<HttpResponseMessage> SendAsync(
HttpRequestMessage request,
CancellationToken cancellationToken)
{
AuthenticationHeaderValue authValue = request.Headers.Authorization;
if (authValue != null && !String.IsNullOrWhiteSpace(authValue.Parameter))
{
api_login parsedCredentials = ParseAuthorizationHeader(authValue.Parameter);
if (parsedCredentials != null)
{
Thread.CurrentPrincipal = PrincipalProvider
.CreatePrincipal(parsedCredentials.username, parsedCredentials.password);
}
}
return base.SendAsync(request, cancellationToken)
.ContinueWith(task =>
{
var response = task.Result;
if (response.StatusCode == HttpStatusCode.Unauthorized
&& !response.Headers.Contains(BasicAuthResponseHeader))
{
response.Headers.Add(BasicAuthResponseHeader
, BasicAuthResponseHeaderValue);
}
return response;
});
}
private api_login ParseAuthorizationHeader(string authHeader)
{
string[] credentials = Encoding.ASCII.GetString(Convert
.FromBase64String(authHeader))
.Split(
new[] { ':' });
if (credentials.Length != 2 || string.IsNullOrEmpty(credentials[0])
|| string.IsNullOrEmpty(credentials[1])) return null;
return new api_login()
{
username = credentials[0],
password = credentials[1],
};
}
private bool Authenticate(HttpContextBase context)
{
if (_RequireSsl && !context.Request.IsSecureConnection && !context.Request.IsLocal) return false;
if (!context.Request.Headers.AllKeys.Contains("Authorization")) return false;
string authHeader = context.Request.Headers["Authorization"];
IPrincipal principal;
if (TryGetPrincipal(authHeader, out principal))
{
HttpContext.Current.User = principal;
return true;
}
return false;
}
private bool TryGetPrincipal(string authHeader, out IPrincipal principal)
{
var creds = ParseAuthHeader(authHeader);
if (creds != null)
{
if (TryGetPrincipal(creds[0], creds[1], out principal)) return true;
}
principal = null;
return false;
}
private string[] ParseAuthHeader(string authHeader)
{
if (authHeader == null || authHeader.Length == 0 || !authHeader.StartsWith("Basic")) return null;
string base64Credentials = authHeader.Substring(6);
string[] credentials = Encoding.ASCII.GetString(Convert.FromBase64String(base64Credentials)).Split(new char[] { ':' });
if (credentials.Length != 2 || string.IsNullOrEmpty(credentials[0]) || string.IsNullOrEmpty(credentials[0])) return null;
return credentials;
}
private bool TryGetPrincipal(string userName, string password, out IPrincipal principal)
{
api_login user = Repository.Validate2(userName, password);
if (user != null)
{
principal = new GenericPrincipal(new GenericIdentity(user.username));
return true;
}
else
{
principal = null;
return false;
}
}
User class methods:
public api_login GetData(string userName)
{
return db.api_login.FirstOrDefault(c => c.username == userName);
}
public api_login Validate2(string userName, string Password)
{
return db.api_login.FirstOrDefault(u => u.username == userName && u.password == Password);
}
Many thans for your help and time.
|
|
|
|

|
It looks like some of that code has come from this blog post[^], but you're missing the PrincipalProvider property, the IProvidePrincipal interface, and the implementation of that interface.
You've got quite a few methods which don't appear to be called. Your RequireSsl property is only used from the Authenticate method, which is never called.
Looking at the Validate2 method, it appears you're storing passwords in plain text, which is a very bad idea. You should be storing salted hashes of the password:
Salted Password Hashing - Doing it Right[^]
Removing the unused methods and property, it looks like you need to use your TryGetPrincipal method instead of PrincipalProvider.CreatePrincipal to get the IPrincipal for the request:
public class BasicAuthMessageHandler : DelegatingHandler
{
private const string BasicAuthResponseHeader = "WWW-Authenticate";
private const string BasicAuthResponseHeaderValue = "Basic";
[Inject]
public iUser Repository { get; set; }
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
AuthenticationHeaderValue authValue = request.Headers.Authorization;
if (authValue != null && !String.IsNullOrWhiteSpace(authValue.Parameter))
{
api_login parsedCredentials = ParseAuthorizationHeader(authValue.Parameter);
if (parsedCredentials != null)
{
IPrincipal principal;
if (TryGetPrincipal(parsedCredentials.username, parsedCredentials.password, out principal))
{
Thread.CurrentPrincipal = principal;
}
}
}
return base.SendAsync(request, cancellationToken).ContinueWith(task =>
{
var response = task.Result;
if (response.StatusCode == HttpStatusCode.Unauthorized && !response.Headers.Contains(BasicAuthResponseHeader))
{
response.Headers.Add(BasicAuthResponseHeader, BasicAuthResponseHeaderValue);
}
return response;
});
}
private api_login ParseAuthorizationHeader(string authHeader)
{
string[] credentials = Encoding.ASCII.GetString(Convert.FromBase64String(authHeader)).Split(new[] { ':' });
if (credentials.Length != 2 || string.IsNullOrEmpty(credentials[0]) || string.IsNullOrEmpty(credentials[1])) return null;
return new api_login()
{
username = credentials[0],
password = credentials[1],
};
}
private bool TryGetPrincipal(string userName, string password, out IPrincipal principal)
{
api_login user = Repository.Validate2(userName, password);
if (user != null)
{
principal = new GenericPrincipal(new GenericIdentity(user.username));
return true;
}
principal = null;
return false;
}
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|

|
I have a requiredfield,range and regular exp validator added and then added each ValidatorCalloutExtender for each validator.
First time when I giving invalid data for rate text box it is showing "This Control is invalid".
Please help. Thanks
|
|
|
|

|
So let me see if I've understood what you're asking:
- You've added a validator to a control.
- You've entered invalid data in the control.
- The validator is now telling you that the data you've entered is invalid.
Sounds like it's working as expected to me.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
 |
|