|
I have a global.asax file, namespace being the project name, and I did check the spelling
in the Global.asax, I have a function called GetWebsiteName(), and in the view I call it.
I did some large project changes yesterday, and I broke things in the program, but have fixed all but this issue.
I'm just scratching my head on this one! I tried searching for anwsers but haven't found anything similar.
namespace coastEnviromental
{
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BinaryDataConfig.RegisterGlobalBinaries();
}
protected void Session_Start(Object sender, EventArgs e)
{
Session["init"] = 0;
}
public static string GetWebsiteName()
{
string pValue = Properties.Settings.Default.WebsiteName;
return pValue;
}
And in the View, the MvcApplication has a red line under it saying that I'm missing an assembly reference.
@{
string websiteName = MvcApplication.GetWebsiteName();
}
If it ain't broke don't fix it
|
|
|
|
|
In most cases, I would love to migrate this code to the Controller part, because a View should only be working with a Model, or ViewModel that is gets passed with. This approach is wrong in the first place, the following might be good,
public ActionResult ActionName() {
ViewBag.websiteName = MvcApplication.GetWebsiteName();
return View();
}
Then in the View, you can use the helper and write it in the HTML content like,
<p>The name of the website is @ViewBag.websiteName.</p>
This would help you out in many ways, as you would be migrating the long running tasks — as well as functions, on the controller and the View would only be generating the HTML for those values.
Although, as for your problem, I could try adding,
@using coastEnvironmental
@{
ViewBag.Title = "My Page";
}
<h4>Content</h4>
<p>Some random stuff</p>
This would work as well, but it is not my recommendation. You should always use the controller for this work, and leave the View to only generate the HTML and not request for anything else — you should also look into the ViewModel or Model-View-ViewModel pattern.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
I thought about that when I wrote it about a year ago.
But I only use it on layout pages for the footer, and on form pages for the website name.
I'll change it.
But I did figure the problem.
The namespace was not listed in the Web.Config file in the views folder
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="coastEnviromental"/>
</namespaces>
If it ain't broke don't fix it
|
|
|
|
|
I am looking for a PDF control that displays the PDF and adds a "submit" button, that send that entire pdf back the server. I want to save the entire pdf as a BLOB on the database. I see a bunch of viewers, but looking for the other half.
Thanks,
mjc
|
|
|
|
|
Absolutely No, @Michael this is not possible as you need to code to save the PDF document in db.
This can be done on submit button click.
|
|
|
|
|
This is for a website that I'm building for my neighbor, and for future builds.
I don't want to use a database in this project, or XML unless I have to.
I thought I might be able to get away with using a binary file with multiple records to store contact us info.
So I have 1 record written so far. I'm trying to read the whole file and just add a record to it.
When I loop through the records, I get an error;
Unable to cast object of type 'System.Collections.Generic.List`1[genericMVC.Models.serialized_contactUs]' to type 'genericMVC.Models.serialized_contactUs'.
I thought I had casted it correctly, but this is the first test of the code, having to fix the issue of opening the file first.
The model is a typical model like in MVC, only I added serialized to the top of the class.
I haven't tried anything yet because I'm not sure if I'm on the right track here; or if my thought is even close to being possible.
string folderPath = HostingEnvironment.MapPath("~/App_Data/Database");
if (Directory.Exists(folderPath) == false)
Directory.CreateDirectory(folderPath);
string binaryPath = folderPath += "\\contactUs_messages.bin";
if (File.Exists(binaryPath))
{
using (var fs = new FileStream(binaryPath, FileMode.Open))
{
if (fs != null)
{
List<serialized_contactUs> data = new List<serialized_contactUs>();
var bf = new BinaryFormatter();
while (fs.Position < fs.Length)
{
serialized_contactUs contact = (serialized_contactUs)bf.Deserialize(fs);
data.Add(new serialized_contactUs()
{
Name = contact.Name,
CompanyName = contact.CompanyName,
EmailAddress = contact.EmailAddress,
Phone_Number = contact.Phone_Number,
Phone_Ext = contact.Phone_Ext,
Phone_Mobile = contact.Phone_Mobile,
MessageContent = contact.MessageContent,
Time_Stamp = contact.Time_Stamp,
Time_Zone = contact.Time_Zone,
RememberMe = contact.RememberMe,
MailingList = contact.MailingList
});
}
bf.Serialize(fs, data);
}
If it ain't broke don't fix it
|
|
|
|
|
 Well I got this to work, but not sure it it's clean and efficient.
But it reads and creates a List<>, adds a record, and writes the list again.
public static Task<bool> contactUs_database_write(model_contactus_request p)
{<br />
try
{
string folderPath = HostingEnvironment.MapPath("~/App_Data/Database");
if (Directory.Exists(folderPath) == false)
Directory.CreateDirectory(folderPath);
string binaryPath = folderPath += "\\contactUs_messages.bin";
if (File.Exists(binaryPath))
{
using (var fs = new FileStream(binaryPath, FileMode.Open))
{
while (fs.Position < fs.Length)
{
var bf = new BinaryFormatter();
List<serialized_contactUs> contacts = (List<serialized_contactUs>)bf.Deserialize(fs);
contacts.Add(new serialized_contactUs()
{
ID = contacts.Count,
Name = p.Name,
CompanyName = p.CompanyName,
EmailAddress = p.EmailAddress,
Phone_Number = p.Phone_Number,
Phone_Ext = p.Phone_Ext,
Phone_Mobile = p.Phone_Mobile,
MessageContent = p.MessageContent,
Time_Stamp = p.Time_Stamp,
Time_Zone = p.Time_Zone,
RememberMe = p.RememberMe,
MailingList = p.MailingList
});
fs.Position = 0;
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(fs, contacts);
}
}
}
else
{
using (var fs = new FileStream(binaryPath, FileMode.CreateNew))
{
List<serialized_contactUs> data = new List<serialized_contactUs>();
data.Add(new serialized_contactUs()
{
ID = 0,
Name = p.Name,
CompanyName = p.CompanyName,
EmailAddress = p.EmailAddress,
Phone_Number = p.Phone_Number,
Phone_Ext = p.Phone_Ext,
Phone_Mobile = p.Phone_Mobile,
MessageContent = p.MessageContent,
Time_Stamp = p.Time_Stamp,
Time_Zone = p.Time_Zone,
RememberMe = p.RememberMe,
MailingList = p.MailingList
});
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(fs, data);
}
}
}
catch (IOException e)
{
if (e.Source != null)
Task.FromResult(false);
}
catch (SerializationException e)
{
if (e.Source != null)
Task.FromResult(false);
}
return Task.FromResult(true);
}
If it ain't broke don't fix it
|
|
|
|
|
I have this model and view, in which instead of the model just being a list of items, it's order information and a list of orders.
So I used StaticPagedList to make a PagedList of the Orders which seems to work fine, and the paginator works as well.
It's the list of Orders in the view, which list all 13 orders instead of the first 5 orders.
I look at the model in the controller and I see the PagedListItems, and a object called "Results View" that has all 13 items.
This is my first time using StaticPagedList, not sure if I'm missing something here or not,
But my question is how do I get orders 1 - 5 and not the whole list.
My Controller Code in which I make the list
model.Orders_PagedList = new StaticPagedList<model_account_order>(model.Orders, pI, sI, model.Orders_Count);
My View Code in which I loop the list
@if (Model.Orders_PagedList.Count() > 0)
{
foreach (var order in Model.Orders_PagedList)
{
string shipTo = "" + order.ShipTo.FirstName + " " + order.ShipTo.LastName + "<br />";
shipTo += order.ShipTo.StreetAddress1 + "<br />";
if (order.ShipTo.StreetAddress2 != string.Empty)
{
shipTo += order.ShipTo.StreetAddress2 + "<br />";
}
shipTo += order.ShipTo.City + " " + order.ShipTo.StateCode + " " + order.ShipTo.PostalCode + "<br />";
shipTo += order.ShipTo.CountryCode + "<br />";
shipTo += "Phone: " + order.ShipTo.PhoneNumber + " " + order.ShipTo.PhoneNumberExt;
If it ain't broke don't fix it
|
|
|
|
|
I've gotta stop figuring this stuff out after I post. I really did work it for an hour and did research as well.
I tried using the intellisense to get "ToPagedList" but nothing showed up until after I hard typed FirstItemOnPage LastItemOnPage and it bombed. Then it showed up in intellisense and I used it.
foreach (var order in Model.Orders_PagedList.ToPagedList(Model.Orders_PagedList.PageNumber, Model.Orders_PagedList.PageSize))
If it ain't broke don't fix it
|
|
|
|
|
Dear Concern!
i am using a CR10 i have already draw a line chart with displaying a data labels with 2 decimals points.
my problem is that i have to change a color of last value(data labels) that a point of line chart.
please help me..
|
|
|
|
|
I have been trying to build a webhook receiver and I can't find a single page that takes you through all the steps of creating and configuring a receiver webhook. First, I want to use my own website to be the receiving site (URI) - not Azure. I found what looked like something I could use as a starting point in a tutorial that shows how to set up a webhook using MS ASP.Net Receiver found in NuGet. I decided to use Bitbucket assuming that the receiving logic would be the same no matter what application to get it from. In my case I am receiving from JIRA and all I want is just the body JSON package returned - I will parse it myself. I have used Requestb.In to look at the message and I know it is being sent properly.
So I created the Bitbucket solution and published it to my website. I believe I set up all of the code and URL/URI data within that so I could try to receive it. In the tutorial, they put a breakpoint into the solution and magically it breaks when the trigger is set.
I thought I had done the same, but mine never breaks. I have to assume that my receiver isn't listening. I have no idea what I need to configure within IIS or the server to make it listen. I also don't know how to make the debugger point to my server instead of Azure.
If I am going about this all wrong please let me know. I am sure I am missing the important part of how to get the server to receive the hook message.
I know I am probably leaving out detail, but since I am at a loss as to what to do you can assume I need to start from scratch and I am in fact a complete novice when it comes to webhooks (and a lot of web stuff).
|
|
|
|
|
|
I am using the Bitbucket one.
|
|
|
|
|
What's the package name? NuGet.org has 35 results for "webhook"[^], and none of them mention "Bitbucket".
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Here is where I got it from https://www.nuget.org/packages/Microsoft.AspNet.WebHooks.Receivers.Bitbucket
And I apologize for the repost. I had a strange error message and then didn't see my post, so I assumed it was not accepted.
|
|
|
|
|
cotsjdixon wrote: I had a strange error message and then didn't see my post, so I assumed it was not accepted.
That'll probably be the automated spam filter. It sometimes flags legitimate messages for review, and needs a human moderator to approve the message.
cotsjdixon wrote: https://www.nuget.org/packages/Microsoft.AspNet.WebHooks.Receivers.Bitbucket
That's the Microsoft package. There's a sample on GitHub[^], but it doesn't seem to have a lot of documentation. There's a link to instructions for setting up the Bitbucket end[^], but not much else.
The documentation[^] looks like a good place to start, as do the various blog posts linked from the project "readme" page.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
NB: The Bitbucket sample does say:
Quote: For security reasons the WebHook URI must be an https URI and contain a 'code' query parameter with the same value as configured in the MS_WebHookReceiverSecret_Bitbucket application setting. The 'code' parameter must be between 32 and 128 characters long.
If you're trying to debug this locally, you probably haven't got a valid certificate and a public https URI.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I have looked at the documentation and I don't see anything that says how to get the website to respond when the webhook comes in. I published the app into a website I created, but I have no idea if that makes it work or not. It seems like I should need to register a service somewhere, but I don't know how or where. The process as I got it from NuGet doesn't make an exe - just dlls. I am not sure what to do with them. That is where the documentation is lacking.
As far as using Bitbucket goes - I used the code as an example. The request I am wanting to receive is not from Bitbucket. I removed the security code out of the config file and have the website set up to not use SSL (at least while trying to get this to work). I was thinking (probably incorrectly) that the NuGet is just a shell for receiving a request and that I can tweak it to be more generic and work with my request. I couldn't find a clear example of how to do it generically.
FWIW - here is the link to the tutorial I started with https://www.youtube.com/watch?v=gbr-wZVl6d4
|
|
|
|
|
cotsjdixon wrote: It seems like I should need to register a service somewhere, but I don't know how or where.
That sounds right to me. As I said, the Bitbucket sample has a link that explains how to register your webhook with Bitbucket[^]; there will presumably be something similar for whatever site you're using.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I guess I am not expressing myself properly. In the bitbucket documentation one of the steps is "6.Enter the URL to the application or server". This is saying that Bitbucket is sending the request somewhere, which should be my "application or server". I am using JIRA instead of Bitbucket to send the hook request out, and as I said I can see that it does get triggered when I have the URL set to RequestBin. However, what I am not understanding is how I get my "application or sever" configured to receive the message coming from the Bitbucket (or JIRA) trigger/request. So registering it with Bitbucket isn't my problem, it is how I get my server or application to receive so I can then do what I need to with it?
|
|
|
|
|
ASP.NET WebHooks receivers | Microsoft Docs[^]
ASP.NET WebHooks handlers | Microsoft Docs[^]
It sounds like some senders are more complicated, but the basic principal is that the sender makes a request to the URI on your server, which is mapped to an action on a WebHooks controller. That controller then validates the request, and passes it through to your custom handlers. Your custom handlers can then do whatever they need to do.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I have started over using the Custom Webhook asp.net receivers but I am still having issues. How do I get the webhooks to run in http not https (no SSL)? All the examples I see say you should use security but they don't say you must use security. Right now the application I am trying to send the hook from is getting errors back saying it must be SSL but the application doesn't use SSL. I have my website set up through IIS to not have SSL turned on, but the application sending the hooks always gives the SSL errors. It worked fine sending the unsecured hook to RequestBin, but it always gets errors trying to get to my unsecured site. I have removed the application key to keep from having to use secrets.
How do I turn off the SSL for the hook receiver?
|
|
|
|
|
According to this page[^], "almost all WebHook providers required that URI should be public and with SSL support".
If you're getting an error message telling you that the provider requires SSL, then I'd be inclined to believe it.
For internal sites, you might be able to use a self-signed certificate. Otherwise, see if you can get a free certificate from Let's Encrypt[^].
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
It is our website that I am putting the receiver on, not someone else's. I have one site within the server that is SSL, but the site I created I have SSL turned off. Can I have one site secure and one site unsecure on the same server? I would have thought that if I have not turned on SSL it would not ask for it from the sender.
|
|
|
|
|
As I said, according to the documentation, most senders require SSL for security.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|