|
A tag helper would be a fairly simple way to do this:
[HtmlTargetElement(Attributes = ViewBagKeyAttributeName)]
public class HtmlElementAttributeTagHelper : TagHelper
{
private const string ViewBagKeyAttributeName = "asp-attributes-key";
[ViewContext]
[HtmlAttributeNotBound]
public ViewContext ViewContext { get; set; }
[HtmlAttributeName(ViewBagKeyAttributeName)]
public string AttributesKey { get; set; }
public override void Process(TagHelperContext context, TagHelperOutput output)
{
if (!string.IsNullOrWhiteSpace(AttributesKey))
{
var attributes = ViewContext.ViewData[AttributesKey];
switch (attributes)
{
case IDictionary<string, object> dict:
{
foreach (var attr in dict)
{
output.Attributes.Add(attr.Key, attr.Value);
}
break;
}
case object obj:
{
foreach (var attr in HtmlHelper.AnonymousObjectToHtmlAttributes(obj))
{
output.Attributes.Add(attr.Key, attr.Value);
}
break;
}
}
}
}
} In Views\_ViewImports.cshtml , add a line to register the tag helper:
...
@addTagHelper *, YourProjectAssemblyName In Views\Shared\Layout.cshtml , add the tag helper to the body:
<body asp-attributes-key="BodyAttributes"> In your controller or view, store the body attributes in the ViewData (or ViewBag , which is basically the same thing):
ViewData["BodyAttributes"] = new Dictionary<string, object>
{
["ng-app"] = "",
...
};
ViewBag.BodyAttributes = new
{
ng_app = "",
...
}; Any attributes you add to the ViewData collection will be combined with any existing attributes on the body element.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I read up on Tag Helpers, and it looked so complicated compared to the old way.
So what folder would I place that in to stay organized?
Like ViewComponents?
FYI:
I'm slowly getting my stuff from the 2nd project wired up in the first project.
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
I tend to put mine in a folder called "Helpers", but there's no specific requirement. Just so long as you're consistent, you can put them wherever you want.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I decided to take up .Net Core 2.1 and port over a project to it, which now seems like a bad idea.
I've noticed that some of the support in system.web has been deleted such as
HttpContext to get querystrings, Request.Url, Session Value, Request.Headers for User Agent
HttpCookies
And reading the Web.Config file that doesn't exist anymore.
My original project design had a separate project that contained extra controllers, controller Attributes, security Attributes
and used the above to operate. it also contained the Entity Framework context, models, seeds, etc and needs a connection; and contains all the email stuff as well which requires access to appSettings.json.
I haven't been able to run the new app yet, for I'm refactoring the external .net core 2.1 project.
My question is, will I end up learning that I can't load dependency injections from the primary project to the secondary project?
Won't be able to load connection strings, and I'll have to move parts back to the primary project?
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
Maybe take advice from your own signature
|
|
|
|
|
No Joke because it's not broken.
This is for job training. Here in my area, Employers are looking for .Net MVC people that know MVC 5, Core 2 and AngularJS 2 through 5., NodeJS and more. I'm just trying to keep up with the bar since it's been raised again.
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
jkirkerx wrote: My question is, will I end up learning that I can't load dependency injections from the primary project to the secondary project? Simple answer: no.
If anything, DI is easier in ASP.NET Core than in previous versions, because it's baked-in. Just declare the dependencies in your constructor, and register your services in the Startup.ConfigureServices method, and the framework will wire everything together for you.
(If you don't want to explicitly register every single implementation of a service, you can use something like Scrutor[^] to find and register all implementations in an assembly.)
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks Richard.
I didn't want to find out at the end that it could not be done and have to start again.
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
Hi,
Iam converting Html page to pdf using html2canvas.js and jspdf.debug.js but images are not exporting to pdf.Can anyone help me to overcome this issue.
Thanks in Advance.
|
|
|
|
|
I'm scratching my head on this one.
Decided to learn ReactJS and did the tutorial on Tutorial (ASP.NET Core) | ReactJS.NET on ReactJS.Net. I did the client side, and then implemented the server side, but I can't get the server side to render the HTML from the ReactJS file.
In ReactConfig, I loaded all the scripts here, but I really only need the server version of the script.
ReactSiteConfiguration.Configuration = new ReactSiteConfiguration()
.AddScript("~/js/remarkable/dist/remarkable.min.js")
.AddScript("~/ReactJS/HelloWorld.jsx")
.AddScript("~/ReactJS/ReactJS_Client.jsx")
.AddScript("~/ReactJS/ReactJS_Server.jsx");
I loaded my scripts in my Section, that loads at the bottom of the page.
This may sound confusing, but I loaded the client version of the script here. I did this because the server side script is different.
<script src="~/js/bundle_ReactJS_Production.min.js"></script>
<script src="@Url.Content("~/ReactJS/ReactJS_Client.jsx")"></script>
@Html.ReactInitJavaScript()
So down later in the View, I have my little ReactJS section, in which the documentation says I need to use this object for server side rendering.
But it crashes with a blank page on the IIS server, and I can't figure out why. I take it out, and the page loads fine but executes the client version instead. I checked the page source and the ReactJS HTML wasn't there.
All I can think of is that I'm missing something in the deployment, but what?
Or I need to add something to the web server.
<div class="container">
<div class="media-container-row">
<div class="col-12 col-md-10" id="content">
<!-- This will render the component server-side -->
@Html.React("CommentBox", new
{
initialData = Model,
url = Url.Action("/Home/Comments"),
submitUrl = Url.Action("/Home/AddComment"),
pollInterval = 15000
})
</div>
</div>
</div>
If it ain't broke don't fix it
Discover my world at jkirkerx.com
modified 21-Jun-18 13:57pm.
|
|
|
|
|
I finally figured it out.
Diving into ReactJS.net is confusing, until you get a complete understanding of how it works on the server side.
So the ReactJS.Net package seems to be something that was working a couple of years ago, but has been upgraded with new packages or DLL's that are more refined. So it's one thing to do the tutorial to get the client side working, and a whole different story to get the server side working.
What it boiled down to, as far as it not working on my server was the Chakra Engine or simply server side rendering. I'm running server core with no browser, and the Javascript rendering engine needs Internet Explorer or Edge to render server side (That's why it worked on my desktop). If you don't have it loaded, then you have to build your project with an JavacriptEngineBuilder which comes in many flavors, and create a JavascriptEngineSwitcher configuration.
Last but not least, is the Remarkable. This is what ran me through the hoops for hours. Loading ReactJS files n ReactSiteConfiguration is not required, you just need remarkable and your jsx scripts.
This deems an article to be written on the subject.
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
Hi,
Am working on Converstion of html to pdf using Html2pdf.bundle.js but am getting Blurry Pdf Output.Can anyone suggest me to overcome this error.
Thanks in advance.
|
|
|
|
|
I had the same issue when working with that library. I ultimately opted to render my pdfs on the server side; I didn't find a good resolution.
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli
|
|
|
|
|
Hi,
Iam working on asp.net application that converts Html to pdf using JsPdf.debug.js and Html2Pdf.js. When the page is loaded in iframe loosing the style for table border.
Please Check the below link for screenshot.
https:
<script src='scripts/jspdf.debug.js'></script>
<script src='scripts/html2pdf.js'></script>
<script>
var pdf = new jsPDF('p', 'pt', 'letter');
var canvas = pdf.canvas;
canvas.height = 72 * 11;
canvas.width = 72 * 8.5;;
html2pdf(document.body, pdf, function (pdf) {
var iframe = document.createElement('iframe');
iframe.setAttribute('style', 'position:absolute;right:0; top:0; frameborder=1; bottom:0; height:100%; width:500px');
document.body.appendChild(iframe);
iframe.src = pdf.output('datauristring');
}
);
</script>
Thanks in Advance.
|
|
|
|
|
|
Html2Pdf.js is not showing the table borders in iframe.
Thanks in Advance
|
|
|
|
|
Hi,
In my ASP.NET Webform page, I have a fileuploader and a div. On single selection of image, the selected image is added to the div. All works fine. Now, I would like to add a checkbox or some sort of selection and then save the selected images to the server folder. Please can someone help on how to do it?
Thanks
|
|
|
|
|
I'm not exactly sure if I follow your correctly. Do you want to implement multiple image uploads?
|
|
|
|
|
Wher did you stuck exactly to add checkbox on each uploaded image or to save them when selected. You have to share your code so anyone can help to resolve error. No one will be writting it for you.
modified 20-Sep-20 21:01pm.
|
|
|
|
|
I need to control the execution sequence of a suite of specflow tests.
I know this is not advised because each test should be completely independent.
But each test involves a common ETL step that takes from 5 to 30 minutes depending on data volumes.
So I need to split each test in two, run all the pre ETL steps then do the ETL once and finally complete the tests.
How do I implement that?
Ger
|
|
|
|
|
I am working on a MVC application and I am starting to work on a STIG finding. This finding is "Insuring that an application does not maintain a valid state on initialization, shutdown failure.". Basically, what this requires is that if the MVC application failures on startup or shutdown it must not allow for a hacker to read valid application data or information during the failure. I have spent hours looking at how this is prevented in an ASP MVC application and can't find anything. Does anyone know how this is handled in MVC?
|
|
|
|
|
After talking to a couple of people the idea of Application_Error and Authentication logic was discussed but would this really prevent the STIG from being displayed. A great link for Application_Error is below but is this the real solution? Has anyone had experience with this?
https://msdn.microsoft.com/en-us/library/bb397417.aspx
modified 5-Jun-18 7:34am.
|
|
|
|
|
Assuming Rule SRG-APP-000225 from the Application Security and Development Security Technical Implementation Guide (which is really an SRG, silly cybersec people), the current version dated 27APR2018 has a lot of example detail in it. https://iasecontent.disa.mil/stigs/zip/U_ASD_V4R6_STIG.zip
The general idea is that it should not be left "half-open" on failure, so something like a no-op sled cannot push an instruction into the application and bypass authentication. If you are running a basic CRUD app, then IIS will handle this stuff for you, providing you dispose of database connections which you're supposed to do anyway if you're using EF in the Repository/Unit of Work pattern.
By and large, in an MVC.NET application all you can really do is make sure that any operational statics are cleared (or reset as part of an application restart/correction process) and that un-managed resources are properly disposed as part of the failure. You can wrap all of this into a failure handler that can attempt to self-correct and, failing that, fail closed.
This all said, if an auditor declared it a finding then they should have given you some sort of finding detail.
If you need detailed support or code review, I'm in the GAL.
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli
|
|
|
|
|
Hello,
Anyone knows how to create a text file in client machine using asp.net code behind ??
Please suggest me any solution...
Thanks in advance...
|
|
|
|
|
Your code-behind runs on the server. It has no access to the client's file system.
The only way you can "create" a file on the client's computer is to write it to the response with the appropriate headers. The user will then be able to save the file wherever they want. They will also be able to choose not to save the file.
And to pre-empt your next question: no, you can't force them to save the file, and you can't influence where the file is saved. You can provide a default file name, but it's only a suggestion, and the user is free to change it.
Response.ContentType = "text/plain";
Response.AppendHeader("Content-Disposition", "attachment;filename=TheSuggestedFileName.txt");
string sourcePath = Server.MapPath("~/path/to/the/file.txt");
Response.TransmitFile(sourcePath);
Response.End();
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|