|
Banging my head on a likely simple problem...
I'm getting a 405 on a WebSocket connection with WSS but not WS.
Vanilla project in VS with this code. Starting with HTTP works. Starting under HTTPS faults 405.
public static class Program {
public static void Main (string [] args) {
var builder = WebApplication.CreateBuilder ( args );
var app = builder.Build ();
app.UseWebSockets ();
app.MapGet ( "/" , (HttpContext http)
=> http.Response.WriteAsync ($$"""
<script>
self.Socket = new WebSocket(`${location.origin.replace("http", "ws")}/socket`);
</script>
""" ) );
app.MapGet ( "/socket" , Connect);
app.Run ();
}
static void Connect (HttpContext HttpContext) {
_ = HttpContext.WebSockets.AcceptWebSocketAsync ().Result;
}
}
modified 14-Apr-23 11:30am.
|
|
|
|
|
If you google "405 error", you get a description of why it occurs:
How to Fix HTTP Error 405 Method Not Allowed: 11 Methods[^]
But the most likely reason is simple: the remote site does not support HTTPS - so HTTP requests succeed, but secure ones fail. The only cure for that would be to contact the remote admins, and ask them to support HTTPS (which will require a valid certificate). Investigating that is where I'd start.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
This is all in my own environment and https works on the site/server but not with sockets (wss).
This is (basically) code that I had running fine on .Net6, so I'm thinking there could be a config setting. I discovered it when I started upgrading (to WebApplication ) some old (working) apps.
It also works (WSS) when I'm running Fidder. If I close Fiddler, it quits working.
|
|
|
|
|
OriginalGriff wrote: does not support HTTPS - so HTTP requests succeed, but secure ones fail.
I don't think so.
The 405 is a HTTP error. So the HTTP server is responding to the request with that error.
The 'S' means that the protocol is actually HTTP (and thus TCP) with SSL (or perhaps TLS) in place.
The SSL protocol runs on the TCP layer and not the HTTP layer. If SSL is not in place (TCP) then for client server two things can happen
1. The client expects SSL but server is not doing it: Then it results in a timeout in the connection for the client because the client is expecting a response (the SSL protocol) which never happens.
2. The client is not using SSL but the server is: In this case the server ends up closing the socket because the the client never sent the expected SSL protocol messages. Client sees error message along the lines of the 'remote end' closed the socket. But it will not show up until the client attempts to use the socket (so connection worked but then later usage fails.)
|
|
|
|
|
I think I'm getting closer. I found a change in Edge that says it no longer uses the Windows certs - but manages its own. It doesn't seem to pick up my/VS self-gen'ed dev cert. Going to try to figure out how to do a manual import and see if that helps.
|
|
|
|
|
How to get XSI:type in inner class while converting to XML
|
|
|
|
|
You already posted this question in Q&A. There's no need to post it again.
What you do need to do is provide more information about what it is that you're actually trying to do here. That question could mean many things and the solution will depend on what it is that you're trying to do here.
|
|
|
|
|
I want to run a these commands in parallel and get the results as each finishes.
private void Load()
{
_apiProxy.GetNavigationItems(NavigationItemType.Company);
_apiProxy.GetNavigationItems(NavigationItemType.Employee);
_apiProxy.GetNavigationItems(NavigationItemType.Project);
}
What's the right way to do this?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
modified 7-Apr-23 1:17am.
|
|
|
|
|
Why not use three separate await Task.Run commands in sequence?
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I always thought await returns back to the caller, so at the first await, the rest are not fired until the previous one completed
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Sorry - I didn't see the "in parallel" bit in your original post.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
NP, so what's the best way to run them in parallel and wait for results from each one separatly?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
|
As in:
private void Bar()
{
Task.Run(() => { Thread.Sleep(2000); Console.WriteLine("1 done"); Thread.Sleep(2000); }).ContinueWith((x) => { Console.WriteLine("1 complete"); });
Console.WriteLine("one done");
Task.Run(() => { Thread.Sleep(2000); Console.WriteLine("2 done"); Thread.Sleep(2000); }).ContinueWith((x) => { Console.WriteLine("2 complete"); }); ;
Console.WriteLine("two done");
Task.Run(() => { Thread.Sleep(2000); Console.WriteLine("3 done"); Thread.Sleep(2000); }).ContinueWith((x) => { Console.WriteLine("3 complete"); }); ;
Console.WriteLine("all done");
}
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
In this case you can just do:
var companyTask = _apiProxy.GetNavigationItems(NavigationItemType.Company);
var employeeTask = _apiProxy.GetNavigationItems(NavigationItemType.Employee);
var projectTask = _apiProxy.GetNavigationItems(NavigationItemType.Project);
var companies = await companyTask;
var employees = await employeeTask;
var projects = await projectTask;
Of course it is up to the apiProxy (or any method it calls) if it will actually run concurrently.
modified 7-Apr-23 8:29am.
|
|
|
|
|
Kevin Marois wrote: I want to run a these commands in parallel and get the results as each finishes.
First of course you need to figure out how exactly you are going to collect the results. Additional to that you might also consider what you are going to do with the results.
Collecting the results itself has nothing to do with running them in parallel but it does impact how you encapsulate what it is exactly that you want each 'task' to do.
For example if each task just returned a boolean and you wanted to return that to the caller then you need a structure that holds a boolean and something that tells you which task returned which boolean. It can get way more complicated than that. For example if each one returns data in a different format.
Probably a really good idea also to consider what happens if there is an error. Could be an expected error or an unexpected error.
|
|
|
|
|
Assuming you have a list of tasks which return the same type, and you want to process the task results in the order in which they complete, then Stephen Toub has you covered:
Processing tasks as they complete - .NET Parallel Programming[^]
For a small number of tasks, using Task.WhenAny is probably good enough:
var tasks = new List<Task<T>>
{
_apiProxy.GetNavigationItems(NavigationItemType.Company),
_apiProxy.GetNavigationItems(NavigationItemType.Employee),
_apiProxy.GetNavigationItems(NavigationItemType.Project)
};
while (tasks.Count != 0)
{
var t = await Task.WhenAny(tasks);
tasks.Remove(t);
T result = await t;
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi,
How can I have a regex for my .NET app's user password with the following:
Password MUST be a minimum of 10 AND maximum of 50
It should NOT contain space.
It should be MIXED alphabet (upper + lower), numeric and following special characters !@#$%^&*-_+=~
Thanks,
Jassim
www.softnames.com
|
|
|
|
|
RegEx is not a good fit for password rules. You'd be much better off coding each rule separately.
|
|
|
|
|
The problem with using a regex for this is that it gets very, very complex - and that means that when the rules change (and they always do) a horribly complicated and difficult to understand string has to be modified, tested, fixed, tested, and finally released. Which makes maintenance difficult and prone to error.
Instead, use .NET string operations (or individual Regexes) to pick up each individual part:
int numLoCase = ...
int numUpCase = ...
int numSpaces = ...
int numNumeric = ...
int numSpecial = ...
int len = ... And then apply a single if statement to apply the rules:
if (len >= 10
&& len <= 50
&& numSpaces == 0
&& ... You get much more readable code, and more reliable maintenence.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Jassim Rahma wrote: Password MUST be a minimum of 10 AND maximum of 50
It should NOT contain space.
It should be MIXED alphabet (upper + lower), numeric and following special characters !@#$%^&*-_+=~ Tell management to f*** off.
A horse staple is better. Let's do a Zoom where I can explain that fine detail. I will be recording for training purposes only.
Bastard Programmer from Hell
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
probe the next function:
bool IsValidPassword(string password,
int minLength=10,
int maxLength=50,
bool requireLowercase=true,
bool requireUppercase=false,
bool requireNumber=false,
bool requireSimbol=false)
{
if (string.IsNullOrEmpty(password))
{
return false;
}
if (password.Length < minLength || password.Length > maxLength)
{
return false;
}
if (requireUppercase && !Regex.IsMatch(password, "[A-Z]"))
{
return false;
}
if (requireLowercase && !Regex.IsMatch(password, "[a-z]"))
{
return false;
}
if (requireNumber && !Regex.IsMatch(password, "[0-9]"))
{
return false;
}
string pattern= @"[!@#$%^&*()_+\-=\[\]{};':" + "\"" + @"\\|,.<>\/? ~]";
if (requireSimbol && !Regex.IsMatch(password, pattern))
return false;
return true;
}
|
|
|
|
|
What's a simbol?
Bastard Programmer from Hell
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
|
Apart from the above-mentioned problem with the readability of Regex, another problem is that Regex is quite computation-heavy, and due to the fact that it builds underlying state-machine[^] performance penalty is heavier for big strings.
|
|
|
|