|
Here you go: Free SMS[^]
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
|
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
|
|
|
|
|
Thank you so much for clarifying the basicAuthHandler class for me. I really appreciate your help and time. I am working on the validate method ( from user class) on the side, to be able to encrypt the passwords (thank you for providing an framework for storing password).
I am currently stuck on the following logic below and would like to request some of your advice. I would like to be able to pass principal identity name only, not the role. Is this plausible? if not, how would i create role for a user. Would i need to call that within my user class method validate?
private bool TryGetPrincipal(string userName, string password, out IPrincipal principal)
{
api_login user = Repository.Validate2(userName, password);
if (user.username != null)
{
principal = new GenericPrincipal(new GenericIdentity(user.username));
return true;
}
principal = null;
return false;
}
}
Many thanks for your time and help.
|
|
|
|
|
If you don't want to specify any roles for the principal, just pass null to the roles parameter:
principal = new GenericPrincipal(new GenericIdentity(user.username), null);
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi Richard,
Thank you so much for help with prior issue with the basic authentication. I am trying to add error messages/exceptions, if the user has either failed to Login or if user credentials are blank. In the code below, I am using throw new HttpResponseException(HttpStatusCode.Unauthorized); , and this currently not showing up for failing user log-ins. I am testing this on the built-in 'values' api controller class by using the '[authorize]' function on top of the values api controller class.
private bool TryGetPrincipal(string userName, string password, out IPrincipal principal)
{
api_login user = repository.Validate2(userName, password);
if (user.username != null)
{
principal = new GenericPrincipal(new GenericIdentity(user.username), null);
}
else if (user.username == null)
{
throw new HttpResponseException(HttpStatusCode.Unauthorized);
}
principal = null;
return false;
}
This is what my BasicAuthHandler class currently looks like. I am not sure whether i would need to create and I am currently not getting anything on the client-side if user credentials are null or pressed cancel on the login dialog.
public class BasicAuthHandler : DelegatingHandler
{
private const string BasicAuthResponseHeader = "WWW-Authenticate";
private const string BasicAuthResponseHeaderValue = "Basic";
public BasicAuthHandler(iUser repository)
{
this.repository = repository;
}
[Inject]
iUser repository { get; set; }
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
AuthenticationHeaderValue authValue = request.Headers.Authorization;
if (authValue == null || authValue.Scheme != BasicAuthResponseHeaderValue)
{
return Unauthorized(request);
}
string[] credentials = Encoding.ASCII.GetString(Convert.FromBase64String(authValue.Parameter)).Split(new[] { ':' });
if (credentials.Length != 2 || string.IsNullOrEmpty(credentials[0]) || string.IsNullOrEmpty(credentials[1]))
{
return Unauthorized(request);
}
api_login user = repository.Validate2(credentials[0], credentials[1]);
if (user == null)
{
return Unauthorized(request);
}
IPrincipal principal = new GenericPrincipal(new GenericIdentity(user.username, BasicAuthResponseHeaderValue), null);
Thread.CurrentPrincipal = principal;
HttpContext.Current.User = principal;
return base.SendAsync(request, cancellationToken);
}
private Task<HttpResponseMessage> Unauthorized(HttpRequestMessage request)
{
var response = request.CreateResponse(HttpStatusCode.Unauthorized);
response.Headers.Add(BasicAuthResponseHeader, BasicAuthResponseHeaderValue);
var task = new TaskCompletionSource<HttpResponseMessage>();
task.SetResult(response);
return task.Task;
}
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.username != null)
{
principal = new GenericPrincipal(new GenericIdentity(user.username), null);
}
else if (user.username == null)
{
throw new HttpResponseException(HttpStatusCode.Unauthorized);
}
principal = null;
return false;
}
}
Many thanks for your time and help.
|
|
|
|
|
I'm not surprised the changes to the TryGetPrincipal method aren't having any effect - you're not calling it anywhere!
The Unauthorized method is sending back a 401 response with the WWW-Authenticate header, which looks like the right way to handle an unauthenticated request.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thank you very much for your advice and help. This put things in perspective. I shall have go at creating custom errors, for invalid user credentials.
Thank you for your support and hard work.
Many thanks.
|
|
|
|
|
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
|
|
|
|
|
I have two button and i want to insert those data into data base in asp.net c#
|
|
|
|
|
What data of your buttons do you want to insert in database ?
Light or darkness, we must choose ...
|
|
|
|
|
On Button Click, use ADO.NET objects to Connect and Execute queries in your Database.
Through the query, insert data to any Database Table.
|
|
|
|
|
I am calling pageMethod in codebehind of aspx page. I get the response for whole page instead of webMethod response. Also, I tried calling the same webMethod using jquery and got the whole page as response.
I am using .NET 4.5.1 and IIS7.5 and I think the issue is realted to in built extensionless URLS in VS2013
i am using the following sys.webserver config
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true">
<remove name="ScriptModule" />
<add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</modules>
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>
can any one send me correct configuration for ASPNET AJAX or Jquery ajax for .NET 4+ and IIS 7+
|
|
|
|
|
i want time table in Gridview...it have in the follwoing format
Date 1,Date 2 ...
Period
7.30-8.30 sub1
8.30-9.30
........
.........
if any one have an idea please share it
|
|
|
|
|
Use label or textbox controls for the "Date1, Date2, ...". Gridview consists of rows of data with some column headers. Here it is in vb (or did you want c#?)
Dim tbl As New DataTable
tbl.Columns.Add("Period", GetType(String))
tbl.Columns.Add("Item", GetType(String))
Dim entry As DataRow = tbl.NewRow
entry("Period") = "7.30-8.30"
entry("Item") = "sub1"
entry = tbl.NewRow
entry("Period") = "8.30-9.30"
entry("Item") = "sub2"
Me.GridView1.AutoGenerateColumns = True
Me.GridView1.DataSource = tbl
Me.GridView1.DataBind()
|
|
|
|
|
I have one!!! At 14:00 I will fetch some ice cream...
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
|
|
|
|
|
I am trying to call the following method (api/test?name=user1) but I keep getting the 'unsuccessful' response. I have tried debugging the method and found it crashes on the 'mes' unsuccessful line. there is data retrieved from the database in the result variable but on the client-end it keeps showing 'unsuccessful' message.
public HttpResponseMessage GetName(string name)
{
User layer = new User();
var result = layer.GetData(name);
if (result.username != null)
{
var mes = string.Format("unsuccessful");
return Request.CreateErrorResponse(HttpStatusCode.NotFound, mes);
}
else
{
return Request.CreateResponse(HttpStatusCode.OK, result);
}
}
Is their something I am missing?
Many thanks.
|
|
|
|
|
miss786 wrote: crashes on the 'mes' unsuccessful line
Crashes? How you get the unsuccessful answer if it crashes?!
From what you wrote it seems, that result.username is not null, so the unsuccessful branch is activated...
OT. Why var mes = string.Format("unsuccessful") and not mes = "unsuccessful"?
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
|
|
|
|
|
miss786 wrote: if (result.username != null) Are you sure you have that test the right way round?
Veni, vidi, abiit domum
|
|
|
|