|
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
|
|
|
|
|
why does this function fails, with CipherMode.OFB where as it works with CipherMode.ECB
Public Function EncryptAES(sIn As String, sKey As String) As String
Dim AES As New RijndaelManaged()
Dim ahashMD5 As New MD5CryptoServiceProvider()
AES.Key = ahashMD5.ComputeHash(System.Text.ASCIIEncoding.ASCII.GetBytes(sKey))
AES.Mode = CipherMode.OFB
Dim AESEncrypt As ICryptoTransform = AES.CreateEncryptor()
Dim aBuffer As Byte() = System.Text.ASCIIEncoding.ASCII.GetBytes(sIn)
Return Convert.ToBase64String(AESEncrypt.TransformFinalBlock(aBuffer, 0, aBuffer.Length))
End Function
Error Message : Specified cipher mode is not valid for this algorithm.
Regards,
Vishal
|
|
|
|
|
Because the RijndaelManaged class doesn't support the OFB cipher mode. It only supports CBC , ECB and CFB .
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
sir can you please guide which aes module for asp.net contains OFB cipher mode
Regards,
Vishal
|
|
|
|
|
There doesn't appear to be anything built-in to .NET which supports using AES in OFB mode. You'll need to find a third-party library to support that.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thank you
Regards,
Vishal
|
|
|
|
|
source code for sending sms in asp.net plz tell me
|
|
|
|
|
|
The gate way http://127.0.0.1 is not working plz give the currently running gateway
|
|
|
|
|
hiii!!! i want to fatch data in list box.. the selection based on dropdown list .. if we select value in drop down then required data will be fatch in list box.. the required data will be fatch accroding to userttype value ..the values of usertype=1,2. i m using 3 layer architecture...
my store procedure
USE [SCJ]
GO
/****** Object: StoredProcedure [dbo].[sp_sendmail] Script Date: 02/10/2014 12:34:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:<author,,name>
-- Create date: <create date,,="">
-- Description:<description,,>
-- =============================================
ALTER PROCEDURE [dbo].[sp_sendmail]
-- Add the parameters for the stored procedure here
(
@usertype INT
--@emailid nvarchar(50)='',
)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
BEGIN
-- Insert statements for procedure here
if(@usertype='usertype')
SELECT emailid from Login_User_Info where LTRIM(RTRIM(usertype)) = LTRIM(RTRIM(@usertype))
END
END
|
|
|
|