|
Richard Deeming wrote: I can't find any reference to "shell" on either of the links I posted.
I don't understand
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
|
I'm sorry. My mistake. I Googled "Let's Encrypt" and got this page.
I'm up to my neck in Google results, and I inadvertently referenced the wrong page.
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
|
Thanks I'll give it a try
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Wow. Hello, My name is Michael. Just call me Mike.
|
|
|
|
|
I'm working on setting up a .Net Framework Web API. I have created a Controller Base class:
public class _ApiControllerBase : ApiController
{
private string connectionString;
public IBizLayer BL { get; set; }
public _ApiControllerBase()
{
connectionString = Properties.Settings.Default.ConnectionString;
BL = new BizLayer(connectionString);
}
}
Next I created a Jobs Controller:
public class JobsController : _ApiControllerBase
{
public int AddJob([FromBody] JobEntity entity)
{
var newJobId = BL.AddJob(entity);
return newJobId;
}
public void DeleteJob(int jobId)
{
BL.DeleteJob(jobId);
}
public IEnumerable GetAllJobs()
{
List results = new List();
results = BL.GetJobsForProject(278).ToList();
return results;
}
public JobEntity GetJob(int Job)
{
return BL.GetJob(Job);
}
public List GetJobsForProject(int projectId)
{
List results = new List();
results = BL.GetJobsForProject(projectId).ToList();
return results;
}
public void UpdateJob([FromBody] JobEntity entity)
{
BL.UpdateJob(entity);
}
}
and my WebApiConfig:
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
}
I have tested all of this with Postman and it seems to work OK.
Any reason not to structure all my controllers this way? Any issues or problems I should be aware of?
Thanks
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
If you're not using it elsewhere within the base class, you can get rid of the private connectionString field.
I'd also be inclined to make the _ApiControllerBase class abstract .
public abstract class _ApiControllerBase : ApiController
{
public IBizLayer BL { get; set; }
protected _ApiControllerBase()
{
string connectionString = Properties.Settings.Default.ConnectionString;
BL = new BizLayer(connectionString);
}
}
Beyond that, if you're happy with the routes containing the entity name, then it's fine. But if you want a proper RESTful service, you'd want the routes to look more like:
GET /api/controller to return the list of all entities;GET /api/controller/{id} to return a specific entity;POST /api/controller to add a new entity;PUT (or PATCH ) /api/controller/{id} to update an existing entity;DELETE /api/controller/{id} to delete an entity;
The GetJobsForProject action would be the exception to this pattern. I'd probably have it as: GET /api/projects/{projectId}/jobs
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
So to follow the REST standard, I would have to decorate each method with the Http Verbs?
Richard Deeming wrote: The GetJobsForProject action would be the exception to this pattern. I'd probably have it as: GET /api/projects/{projectId}/jobs
How would this signature look in the API?
Thanks
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Kevin Marois wrote: So to follow the REST standard, I would have to decorate each method with the Http Verbs?
Yes. But you'd probably want to do that anyway - for example, you don't want actions which modify the data to be available via GET requests.
Kevin Marois wrote: How would this signature look in the API?
Depends on how you set up the routes. For example, if you don't have a RoutePrefix attribute on your controller:
public class JobsController : _ApiControllerBase
{
[HttpGet("api/projects/{projectId:int}/jobs")]
public List<JobEntity> GetJobsForProject(int projectId) { ... }
} However, my gut feeling is that this action would fit better as part of a ProjectsController :
[RoutePrefix("api/projects")
public class ProjectsController : _ApiControllerBase
{
[HttpGet("")]
public IEnumerable<ProjectEntity> GetAllProjects() { ... }
[HttpGet("{id:int}")]
public ProjectEntity GetProject(int id) { ... }
[HttpGet("{id:int}/jobs")]
public IEnumerable<JobEntity> GetJobsForProject(int id) { ... }
[HttpPost("")]
public int AddProject([FromBody] ProjectEntity entity) { ... }
[HttpPut("{id:int}")]
public void UpdateProject([FromBody] ProjectEntity entity) { ... }
[HttpDelete("{id:int}")]
public void DeleteProject(int id) { ... }
}
Attribute Routing in ASP.NET Web API 2 | Microsoft Docs[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hello
Trying to create a Bootstap/PHP modal form that will hold a img/video upload, iframe(external videos), and comment section. Tried to have a comment modal separate from media and its not working. How do I create this? Here is my code:
<pre><button type="button" class="btn btn-link" data-bs-toggle="modal" data-bs-target="#exampleModal"> </label></div>
</div>
</div>
<div class="embed-responsive embed-responsive-16by9 z-depth-1-half">
<iframe class="embed-responsive-item" src="..." allowfullscreen></iframe>
</div>
<div class="form-group">
<label for="inputemail" class="col-lg-2 control-label">Comment</label>
<div class="col-lg-10">
<textarea name="bio" class="form-control" placeholder="..."><?php echo !empty($userData['comment'])?$userData['bio']:''; ?></textarea>
</div>
</div>
<div class="form-group">
<input type="submit" class="btn btn-light" name="proSubmit">
</div>
</div>
</div>
</div>
</div>
</div>
|
|
|
|
|
I have almost zero experience creating a Web API, so bear with me.
I opened VS2019 and created a new ASP.NET Web Application (.Net Framework). It comes with the standard Home and Values controllers.
I hit F5 and it ran. I then used Postman to verify passing "https://localhost:44312/api/Values". I get back the expected results. So far so good.
I then right clicked the project and chose "Publish" and published to a folder. I then copied the contents of the folder to the server and created a new Web Site in IIS pointing to my API and set the port to 44400. I clicked the Browse link in IIS and the browser opened. I added "/api/Values" to the end of the URL and got back this: Click: Here's the result.
I changed NOTHING in the app. Here's the Web.Config, which is what the error seems to be complaining about:
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
https:
-->
<configuration>
<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.7.2" />
<httpRuntime targetFramework="4.7.2" />
</system.web>
<system.webServer>
<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>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" />
<bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
<bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-5.2.7.0" newVersion="5.2.7.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701" />
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+" />
</compilers>
</system.codedom>
</configuration>
First question: Any idea what's wrong?
Next question: How do I turn on/enable better debugging?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
It looks like the configuration is locked down on your server.
Open IIS Manager, double-click on the "Feature Delegation" item in the "Management" group, and find the "Handler Mappings" item. Ensure that it's set to "Read/Write".
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
It doesn't seem to be there in IIS. See pic
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
No, you've double-clicked on "Handler Mappings", not "Feature Delegation".
NB: "Feature delegation" is only available at the root, when you click on the server name. It won't be available within a specific site or application.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Yup, I was wrong. Found it now.
Thanks!
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Hello,
This is my program with the obsolete WebRequest.
Who will help me to set this up with HttpClient.
Thanks in advance, Ger
public ToProgModel ProgCsv(Uri webSiteProg, ToProgModel prog, string complexProg)
{
string ProgTextString;
try
{
var AuthorisatorProg = _config.GetConnectionString("AuthorisatorProg");
var PasswordProg = _config.GetConnectionString("PasswordProg");
#pragma warning disable SYSLIB0014 // Type or member is obsolete
WebRequest webrequest = WebRequest.Create(webSiteProg);
#pragma warning restore SYSLIB0014 // Type or member is obsolete
SetBasicAuthHeader(webrequest, AuthorisatorProg, PasswordProg);
WebResponse webresponse = webrequest.GetResponse();
Stream webstream = webresponse.GetResponseStream();
StreamReader streamreader = new(webstream);
ProgTextString = streamreader.ReadToEnd();
webresponse.Close();
webresponse.Dispose();
streamreader.Dispose();
webstream.Dispose();
}
catch (HttpRequestException ex)
{
prog.Ret = $"Http response EX: {ex.Message}";
return null;
}
return prog;
}
public void SetBasicAuthHeader(WebRequest request, string userName, string userPassword)
{
string authInfo = userName + ":" + userPassword;
authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo));
request.Headers["Authorization"] = "Basic " + authInfo;
}
|
|
|
|
|
For a start, you'll need to make your method async to use the HttpClient class. Which unfortunately means you'll need to make the calling method async , and so on - it's async all the way down.
At the basic level, your code would look something like this:
public async Task<ToProgModel> ProgCsvAsync(Uri webSiteProg, ToProgModel prog, string complextProg)
{
HttpClient client = new HttpClient();
SetBasicAuthHeader(client.DefaultRequestHeaders, AuthorisatorProg, PasswordProg);
using (HttpResponseMessage response = await client.GetAsync(webSiteProg))
{
if (!response.IsSuccessStatusCode)
{
prog.Ret = $"Http response EX: {response.StatusCode}";
return null;
}
string progTextString = await response.Content.ReadAsStringAsync();
...
return prog;
}
}
public void SetBasicAuthHeader(HttpRequestHeaders headers, string userName, string userPassword)
{
string authInfo = userName + ":" + userPassword;
authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo));
headers.Authorization = new AuthenticationHeaderValue("Basic", authInfo);
} There are several improvements you can make to this - for example, using IHttpClientFactory[^] to manage the HttpClient instances.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi Homer, thanks for your response. But I don't see in IHttpClientFactory how to implement "Http Basic Authentication"
So as in my source "
SetBasicAuthHeader(webrequest, AuthorisatorProg, PasswordProg); "
|
|
|
|
|
I included an updated version of that method in my answer.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Sorry Richard,
I had mist in the first moment your update, only see your phrase from Homer.
But now I need to give you many thanks for your UPDATE on my program.
I have installed your update and every thing works nice.
Thank you very much en best regards Ger
|
|
|
|
|
Hi, please pretty much new to web development, I recently developed a little e-commerce website using Node js, express for the backend, and plain HTML and CSS for the front-end. Can anyone help me with a guide on how to take this site to production?
|
|
|
|
|
Choose a web host that has been around for at least 15 or 20 years and contact them and ask them how to get this started. You should get your own dot com and start with the MINIMUM setup that the web host will allow. Then work with the site (your own dot com) for at least 30 days so that you have forced yourself to not rush into it and you have some experience watching the results of your choices.
Do NOT spend a lot of money on options at the web host. Almost everything that they offer to you for money: you can probably do yourself. Except things like getting an SSL certificate, do that after 30 days and pay for it.
Thank you for asking.
|
|
|
|
|
I have pairs of images and their related texts in my web application. My images are small rounded photos that the user can click on each of them to enter a new page. I want to place their specified texts at the center of those thumbnails.
I wrote these codes:
<html lang="fa">
<head>
<title>Information System</title>
<style>
#main-image{
display: block;
margin-left: auto;
margin-right: auto;
max-width: 100%;
max-height: auto;
}
b{
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
color: blue;
}
.sub-image{
border-radius: 5%;
}
.container{
position: relative;
text-align: center;
}
</style>
</head>
<body bgcolor="white">
<div>
<img id="main-image" src="Images/IT.jpg" width="1600" alt="Intro">
</div>
<hr>
<div class="container">
<img class="sub-image" src="Images/repair.jpg" width="300">
<div class="image-text">
Failures
</div>
</div>
<div class="container">
<img class="sub-image" src="Images/Equipment.jpg" width="300">
<div class="image-text">
Equipments
</div>
</div>
</body>
</html>
Please help me.
modified 21-Jul-21 14:01pm.
|
|
|
|
|
Hey you have to write these css code to make text appear over the image and center .
.image-text{position:absolute; top:50%; left:0; width:100%; z-index:10; text-align:center; transform:translateY(-50%);}
You can keep you css as it is.. just paste above css and your text will be over and center. let me know if it work for you.
|
|
|
|